Multiarray
Array of array is called multi dimensional array. general syntax of declaring multidimensional array as follow
data_type array_name[size1][size2]..[sizeN].
for example :-
int A[3][2];
here a is an array of two dimension. To understand multidimensional array in simple way we can think of this way.
above array A is a two dimensional array which is combination of three single dimensional array A[0], A[1] and A[2] which are array of 2 elements. We can also understand that a two dimensional array is an collection of various rows and column.
above exmaple will declare 3 rows and two column.
A[0] A[1] A[2]
Array array array
|—-A[0]—|—-A[1]—-|—- A[2]—–|
array–2 array – 2 array – 2
intialisation of multi dimentional array:-
C provides various way of initialising multidimentional array .
int c[2][2]={{1,2},{3.4}};
int c[][2]={{1,2},{3.4}};
int c[2][2]={1,2,3,4};
Accessing an element in two dimentional array:-
an element in an array are accessed by combination of row index and column index. combination of row index and column index tells the exact positon of element in array.
for example to access the 2nd element from 1st row of array c we can do it by following way
c[0][1];
Example programm of two dimentional array:-
int main()
{
int a[2][2]={1,2,3,4};
printf(“print of above array\n”);
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
printf(“a[i][j]”);
}
printf(“\n”);
}
}
after compiling and executing below program we will get below output
print of above array
1 2
3 4