10.2 Three-Dimensional Arrays
Static arrays of three or more dimensions can be created in C, though, the use of arrays of more than three dimensions is rare.
The syntax for declaring and initializing a 3-D array is similar to that for 1- and 2-D arrays. For example, the array declaration
- int box[3][4][2];
creates a 3-D array that contains 3 tables with each table being comprised of 4 rows and 2 columns. For each additional dimension, the number of elements in the higher dimension is specified immediately after the array name.
Initializing a 3-D array is done in a similar fashion to 2-D array, with the contents of the third dimension being specified within its own pair of curly braces:
- int box[3][4][2] = {
- { {0, 1}, // box[0]
- {2, 3},
- {4, 5},
- {6, 7}
- },
- { {8, 9}, // box[1]
- {10, 11},
- {12, 13},
- {14, 15}
- },
- { {16, 17}, // box[2]
- {18, 19},
- {20, 21},
- {22, 23}
- }
- };
which in a "flat" view can be illustrated as

