# multi-dimensional array

It is a collection of single dimensional array. value is stored as a table from in it. here is syntex below-

SYNTEX:-

`Storage-class data-type array-name[size1][size2][size3].....;`

avoid complexity, here we will discuss about two dimensional array,

`data-type array-name[size1][size2];`

in two-dimensional array  size1 represents row and size2 column.

such as,

Example

`int arr;`

to know how many element store in the two-dimensional array we use size row X column.-

`int arr;`

row × column, then

2×3=6 it will store 6 elements, such as in table form below-

## initialization of two-dimensional array

SYNTEX:-

multi-dimensional array initialization is similar to normal array. i.e-

`data_type array_name[size1][size2]={list};`

Example:-

`int arr={3,2,4,1,6,7};`

or

```int arr={
{3,4.6},
{2,1,7}
};```

as we know, first size as row while second as column, such as, means,

```x = 3
x = 4
x = 6
x = 2
x = 1
x = 7```

In below program, we take the elements from the user and accessing them,

## accessing of two-dimensional array element

Like the single dimensional array, the element of the multi dimensional array is accessed from their index value. But here we use 2 loop.

`int arr;`

You can understand this with the help of the program given below.

```#include<iostream.h>
#include<conio.h>

void main()
{
int i,j,r=1,s=1,x;              // array variable declaration
clrscr();

for(i= 0; i<2; i++)
{
for(j= 0; j<3; j++)
{
cout<<"Enter "<<r++<<" element in x["<<i<<"]["<<j<<"]: ";
cin>>x[i][j];
}
}

cout<<"Displaying array element: ";
for(i= 0; i<2; i++)
{
for(j= 0; j<3; j++)
{
cout<<endl<<s++<<" Element store array in x["<<i<<"]["<<j<<"] is: "<<x[i][j];      // store 5 value at a time
}
}

getch();
}```
```OUTPUT:-
Enter 1 element in x: 2
Enter 2 element in x: 3
Enter 3 element in x: 1
Enter 4 element in x: 5
Enter 5 element in x: 6
Enter 6 element in x: 4

Displaying array element:
1 Element store array in x is: 2
2 Element store array in x is: 3
3 Element store array in x is: 1
4 Element store array in x is: 5
5 Element store array in x is: 6
6 Element store array in x is: 4```

Related Exercise