Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include extern void abc(int *x); extern void abc(int x[20]); extern void abc(int x[]); void abc(int x[3]) { printf(inside abc: size is %d , sizeof(x));
#include
#include
extern void abc(int *x);
extern void abc(int x[20]);
extern void abc(int x[]);
void abc(int x[3]) {
printf("inside abc: size is %d ", sizeof(x));
}
int main() {
int y[15];
printf("outside abc: size is %d ", sizeof(y));
abc(y);
return EXIT_SUCCESS;
}
First, with just a couple of exceptions, any time an array name is given in a program, it is converted (by the compiler) to be a pointer to the first element of the array. The exceptions are when the array is the immediate operand of the sizeof function or the "create-pointer-to" (unary &) operator. The semantics of the [l operator in a [il mean((a)+ (i))) a is converted to be a pointer to its first element, i is added to this pointer, giving a pointer to the element in the ith position of a, and the operator makes the reference One of the anomalies of C is that the semantics of [ allows i [a] to be used as an alternative to a[i]. (You could experiment with this: instead of a [0], write o[a] when you want to access the first element in array a. Just because you can do this does not mean you should in your code... Tammy does not recommend using the 0 [a] form.) Second, any time a function's formal parameter is given as an array type, it is converted (by the compiler) to be a pointer type: "array of int" is converted to "pointer to int": "array of pointer to char" is converted to "pointer to pointer to char" 1. Given this knowledge, examine the program array.c. Compile and run the program. Explain why: no type-check errors are reported for any of the three declarations of the function abc, even though the parameter declarations appear to be inconsistent. The "extern" keyword declares the type for the function abc while the actual function definition is defined once below the three declarations Compile and run the program gcc o array array.c array 2. Why does the array seem to change size when the function is calledStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started