Loading, please wait...

Multi Dimensional Array

An array having more than one subscript variable/index is called multidimensional array. A multidimensional array is an array of array.

 

The multidimensional array contains multiple subscript/index in their declaration, like int matrix[10][20] and char cuboid[30][30][25]; In a multidimensional array, we can access any element using multiple index reference, like matrix[4][8].

 

Two Dimensional array is the most common form of MultiDimensional Array which is usually used for matrices operations having row and columns.

 

Example

/* How to use Multi Dimensional array in C */
#include<stdio.h>

int main()
{
int i, j ;
/* Initialize the value of array */
int myarray[2][2] = {51,  52,  53, 54 };

for(i=0; i<2 ; i++)
{
for(j = 0; j<2; j++)
{
/*Accessing the elements of myarray*/
printf(“Element of myarray[%d][%d] is %d \n”, i, j, myarray[i][j]);
}
}
}

 

Output:

Element of myarray[0][0] is 51

Element of myarray[0][1] is 52

Element of myarray[1][0] is 53

Element of myarray[1][1] is 54