Answered step by step
Verified Expert Solution
Link Copied!

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;

}

image text in transcribed

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 called

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

Explain why Blu-ray discs hold so much more data than regular DVDs.

Answered: 1 week ago

Question

Describe downsizing.

Answered: 1 week ago

Question

12-5 How will MIS help my career?

Answered: 1 week ago