sizeof and multi-dimensional arrays

Lars Wirzenius wirzeniu at cs.Helsinki.FI
Sun Jan 6 09:00:25 AEST 1991


In article <4596 at sactoh0.SAC.CA.US> jak at sactoh0.SAC.CA.US (Jay A. Konigsberg) writes:
>[ char x[5][6]; sizeof(*x) gives 6 ]
>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 *x isn't a pointer, it's an array.  First the the type of x decays
from "array 5 of array 6 of char" into "pointer to array 6 of chars".
(See for example: _Standard_C_, by P.J.Plauger and Jim Brodie, page 74,
or K&R-2, Section A7.1, "Pointer Generation", page 200.)

This pointer is dereferenced with '*', and the result is an array of
type |char [6]|, which has the size 6.
--
Lars Wirzenius    wirzeniu at cs.helsinki.fi    wirzenius at cc.helsinki.fi



More information about the Comp.lang.c mailing list