sizeof and multi-dimensional arrays
Rory Jacobs
rory at maccs.dcss.mcmaster.ca
Sun Jan 6 08:47:21 AEST 1991
In article <4596 at sactoh0.SAC.CA.US> jak at sactoh0.SAC.CA.US (Jay A. Konigsberg) writes:
>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).
>
But it does make sense.
In a sense the array name is a pointer to the array. To access
the i-th element in an array you could write
foo[i]
or
*(foo + i)
Both statements return the i-th element.
Now back to the orignal problem, since the above is true (convient
as pointer arithmatic is faster than array indexing) *x is equivalent
to *(x+0) which is x[0], and thus they have the same size.
Hope this helps,
Rory
Rory Jacobs Who me?!?
rory at maccs.dcss.mcmaster.ca Let's go Flyers!
...!uunet!uati!utgpu!maccs!rory I thought it was easy...
Department of Computer Science and Systems Boring (yawn)!
McMaster University, Hamilton, Ont Let's have some fun.
More information about the Comp.lang.c
mailing list