Using sizeof() on a parameter array
D'Arcy J.M. Cain
darcy at druid.uucp
Sun May 19 22:03:32 AEST 1991
In article <12151 at jarthur.Claremont.EDU> Jim Seidman writes:
>void test(char param[80]) {
> char local[80];
>
> printf("sizeof(param) = %d\n", sizeof(param));
> printf("sizeof(local) = %d\n", sizeof(local));
>}
>Now, I thought that this should print out the same size for both, namely
>80. But according to MSC, local has a size of 80, and param has a size
>of 2 (the size of a pointer).
The assumption that you seem to be making here is that the parameter param
is the entire array. Arrays are not passed in C but rather a pointer to
the initial element of the array. The compiler treats the above as:
void test(char *param)
and if you read it that way the above makes perfect sense.
--
D'Arcy J.M. Cain (darcy at druid) |
D'Arcy Cain Consulting | There's no government
Toronto, Ontario, Canada | like no government!
+1 416 424 2871 |
More information about the Comp.lang.c
mailing list