sizeof and multi-dimensional arrays
Tim Olson
tim at proton.amd.com
Sun Jan 6 08:00:31 AEST 1991
In article <fred.663069060 at prisma> fred at prisma.cv.ruu.nl (Fred Appelman) writes:
| 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.
That is correct, but the first sizeof is '*x', not 'x'. Thus, it
appears to be a compiler bug -- they both should result in '3'.
--
-- Tim Olson
Advanced Micro Devices
(tim at amd.com)
More information about the Comp.lang.c
mailing list