sizeof and multi-dimensional arrays

Fred Appelman fred at prisma.cv.ruu.nl
Sat Jan 5 20:51:00 AEST 1991


In <1991Jan5.050613.22303 at Neon.Stanford.EDU> dkeisen at Gang-of-Four.Stanford.EDU (Dave Eisen) writes:

>Is the following a compiler bug or am I just confused?
>
>char x[2][3];
>
>  sizeof (*x)          gives 6
>  sizeof (x[0])        gives 3.
>
>What's the scoop?
>

You are just confused. 
'x' is a two dimensional array of 2*3 elments of type char. Makes a total of
6. 'x[0]' and 'x[1]' are arrays with a length of 3 elements. So both arrays
have a size of 3.

Fred
-- 
Fred J.R. Appelman, 3D Computer Vision, Utrecht University
AZU, Heidelberglaan 100, 3584 CX Utrecht, The Netherlands.
Telephone: +31-30-506710 Fax: +31-30-513399
e-mail: fred at cv.ruu.nl or appelman at cs.unc.edu



More information about the Comp.lang.c mailing list