Multi-Dimesnional Array
Multi-Dimesnional Array
1
2
Two-Dimensional Arrays
4
5
7
Initialization
Like one-dimensional arrays
Two-dimensional arrays can be initialized
when they are declared
To initialize a two-dimensional array when
it is declared
1. Elements of each row are enclosed within
braces and separated by commas
2. All rows are enclosed within braces
3. For number arrays, if all components of a row
are not specified, the unspecified components
are initialized to zero
8
Processing a 2-D
Array
A one-dimensional array is usually processed via a for loop. Similarly, a two-
dimensional array may be processed with a nested for loop:
Each pass through the inner for loop will initialize all the elements of the current row to 0.
The outer for loop drives the inner loop to process each of the array's rows.
Initializing in
Declarations
int Array1[2][3] = { {1, 2, 3} , {4, 5, 6} };
int Array2[2][3] = { 1, 2, 3, 4, 5 };
int Array3[2][3] = { {1, 2} , {4 } };
Rows of Array1:
1 2 3 for (int row = 0; row < 2; row++)
4 5 6 {
13
FIGURE 8-40 A Three-dimensional Array (3 x 5 x 4)
14
C View of Three-dimensional Array
15