Two dimensional array:
The array which is used to represent and store data in a tabular form is called as two dimensional array. Such type of array is specially used to represent data in a matrix form.
Initialization can be done as design time or runtime.
1. Design time: This can be done by providing „row X column‟ number of elements to the array. Eg for a 3 rows and 4 columns array , 3X4=12 elements can be provided as :
arr[3][4]={ {2,3,4,6},
{1,4,6,3},
{6,6,4,3},
{6,7,8,9}
};
2. Runtime: For this loop structures like „for‟ can be used in a nested form, where outer loop will increment row and inner loop will increment column.
Eg :
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf(“%d”, &arr[i][j]);
}
}
Example:
main()
{
int arr[2][2]={{1,2},{4,5});
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf( “%d”, arr[i][j]);
}
printf(“\n”);
}
}