On Sat, 9 Jan 1999, Yasushi Shoji wrote:

> in the function sub i is 4,
> and in main, it's 12.

That makes sense, when both your ints and pointers are 4 bytes 
wide. 

In main(), sizeof(a) says 12 because a is the address
of an array of 3 ints (3*4=12). In sub(), a equals 4 because
it is a pointer to an int. Do you see the difference ?

The book you are reading covers the subject, but I don't
know where. 

> is it because C passes the value of a to the
> function sub?
> even though function sub is sub(int a[3])?
>                                     ^^^

Passing arrays isn't something that is normally possible
in C, instead the address of an array is passed. You can
pass structures though.

> is there any way to get size of a[] in sub function?


void sub(int *a, int a_size);

Or you can always place the size of the array in
the being of the array. Or use a structure containing
a pointer to the array and the size of the array.


Reply via email to