sizeof and multi-dimensional arrays
Shiping Zhang
ping at cubmol.bio.columbia.edu
Sun Jan 6 13:31:16 AEST 1991
In article <4596 at sactoh0.SAC.CA.US> jak at sactoh0.SAC.CA.US (Jay A. Konigsberg) writes:
>Also I bumped the array to "char x[5][6]" and got:
>sizeof(x[0])=6
>sizeof(*x)=6
>sizeof(x)=30
>This seems to be one of the finer differences between pointers and arrays.
...
>sizeof(x[0]) makes sense as it returns the total size of that dimmension
> of the array.
>
>sizeof(*x) DOES NOT make sense. The size of a pointer on this machine
> is 4 bytes. (Note: adding "char *y; sizeof(y) does return 4).
For an array x, *x is equivalent to x[0], so sizeof(x[0]) and sizeof(*x)
should get the same number. Don't be confused with the difference
between *x and &x. *x means a point in a declaration, but not in an
expression.
-ping
More information about the Comp.lang.c
mailing list