Expert C Programming

(Jeff_L) #1

Arrays in C Are One-Dimensional


Whenever you see "array" in C, think "vector," that is, a one-dimensional array of
something, possibly another array.


How Multidimensional Arrays Break into Components

Note carefully how multidimensional arrays can be broken into their individual component arrays. If
we have the declaration


int apricot[2][3][5];


this tells us that the same storage can be looked at in any of the ways


shown in Figure 9-8.


Figure 9-8. Multidimensional Array Storage

Normally, one assigns between two identical types, integer to integer, double to double, and so on. In
Figure 9-8, we see that each individual array within the array-of-array-of-arrays is compatible with a
pointer. This is because an array-name in an expression decays into a "pointer-to-element" (Rule 1 on
page 242). In other words, you can't assign an array to something of the same type because an array
cannot be assigned to as a whole. You can load a pointer with the value of the array-name because of
the "array-name in an expression decays into a pointer" rule.

Free download pdf