Multi or Three dimensional Arrays
In practice, one rarely uses three-dimensional arrays. A three dimensional array can be thought of as an array of arrays.
Syntax: - data_type arrayname [S1][S2][S3].... [Sn]
Where Sn is the size of the nth dimensions. Three-dimensional array can be initializing as follows.
int mat [3][3][3] = {
{
{1,2,3},
{4,5,6},
{7,8,9}
},
{
{1,3,5},
{4,9,7},
{7,4,2}
},
{
{1,4,3},
{1,0,6},
{7,7,9}
}
};
In this array a one-dimensional array of three elements is constructed first. Then three such one-dimensional arrays are placed one below the other to give a two dimensional array containing three rows. Then three such two dimensional arrays are placed one behind the other to yield a three dimensional array containing three 2 dimensional arrays. As one and two-dimensional arrays it is also stored linearly in the memory as shown below.
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
1
|
3
|
5
|
4
|
9
|
7
|
7
|
4
|
2
|
1
|
4
|
3
|
1
|
0
|
6
|
7
|
7
|
9
|