C Programming language

adplus-dvertising
Arrays in C: Multidimensional Arrays
Previous Home Next

Multidimensional Array

An array with more than one index value is called a multidimensional array. All the array above is called single-dimensional array. To declare a multidimensional array you can do follow syntax:

data_type array_name[][][]; 

The number of square brackets specifies the dimension of the array. For example to declare two dimensions integer array we can do as follows:

int matrix[3][3];  

Initializing Multidimensional Arrays

You can initialize an array as a single-dimension array. Here is an example of initialize an two dimensions integer array:

1. int matrix[3][3] =
2. {
3. {11,12,13},
4. {21,22,23},
5. {32,31,33},
6. }; 

Two dimensional arrays

Multidimensional array have two or more than two indexes values which specify the element in the array.

i.e., multi[i][j].
Where [i] specify row and [j] specify column
Declaration and calculation:
int a[10][10];
int b[2][2];        // int b [2][2]={{0,1},{2,3}}
Sum = a[10][10]+b[2][2]  

Array and Pointer

Each array element occupies consecutive memory locations and array name is a pointer that points to the first element. Beside accessing array via index we can use pointer to manipulate array. This program helps you visualize the memory address each array elements and how to access array element using pointer.

Previous Home Next