Table of Contents
What is Multi Dimensional 3D Arrays and Declaration, Initialization of Multi Dimensional Array in Data Structure using C and C++
What is Multi Dimensional 3D Array in Data Structure Using C and C++
C language also facilitates the arrays of three or more dimensions depending on compiler. The Multi Dimensional array is controlled by multiple subscripts. @ upbed.in
Declaration of Multi Dimensional Arrays in Data Structure Using C and C++
We can declare a multidimensional array as follows in general:
data type array name[size 1] [size 2] [size ]………[size n]
We can think of a 3-D array of 2-D arrays. For Example if we have an array-
int ar[2][4][3] ;
We can think of this as an array which consists of two 2-D arrays and each of those 2-D arrays has four rows and 3 columns.
[0]
[0][0] | [0][1] | [0][2] |
[1][0] | [1][1] | [1][2] |
[2][0] | [2][1] | [2][2] |
[3][0] | [3][1] | [3][2] |
[1]
[0][0] | [0][1] | [0][2] |
[1][0] | [1][1] | [1][2] |
[2][0] | [2][1] | [2][2] |
[3][0] | [3][1] | [3][2] |
The individual elements are-:
ar[0][0][0], ar[0][0][1], ar[0][0][2], ar[0][1][0],………………………….ar[0][3][2]
ar[1][0][0], ar[1][0][1], ar[1][0][2], ar[1][1][0],……….…………………ar[1][3][2]
The total number of elements in the above array = 2 * 4 * 3 = 24
Initialization of Multi Dimensional Array in Data Structure using C and C++
The initialization of 3-D array is as follows:
int ar[2][4][3] = { { { 1, 2, 3 } , { 6, 6, 9 } , { 5, 0, 9 } , { 3, 6, 2 } }, { { 2, 9, 0 } , { 4, 7, 3 } , { 6, 4, 6 } , { 5, 9, 2 } } }