Book
Collection
Click for Table of Contents
© 2025 by Rance D. Necaise
C Primer for Python Programmers
Copyright © 2025
Rance D. Necaise

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

  1. 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:

  1. int box[3][4][2] = {
  2.          { {0, 1},      // box[0]
  3.            {2, 3},
  4.            {4, 5},
  5.            {6, 7}
  6.          },          
  7.          { {8, 9},      // box[1]
  8.            {10, 11},
  9.            {12, 13},
  10.            {14, 15}
  11.          },
  12.          { {16, 17},    // box[2]
  13.            {18, 19},
  14.            {20, 21},
  15.            {22, 23}
  16.          }  
  17.       };

which in a "flat" view can be illustrated as

Question 10.2.1

Provide an array declaration to create a 3-D array named multi that can store floating-point values organized into 7 tables, with each table comprised of 10 rows and 12 columns.

  1. float multi[7][10][12];