Arrays with two sets of square brackets [][] are called two-dimensional arrays. A two dimensional array is used when data items are arranged in row-wise and column-wise in a tabular form.
The array has two sets of square brackets [3][4], and hence it is a 2 dimensional array with 3 rows and 4 columns.
This declaration informs the compiler to reserve 12 locations(3*4=12)contiguously one after the other.
Initialization of two dimensional array.
Assigning required value to a variable before processing is initialization. As we initialize a variable to the required value we can initialize the individual elements of a 2 dimensional array during initialization.
Syntax:-
data type array_name[rows][cols]={ {a1,a2,a3...an}, {b1, b2, b3...bn}, };
Example :- int arr[2][3]={ {33, 55, 66}, {23, 33, 12}, };
Q.) W.A.P to enter elements of an array and print it.
#include<stdio.h>
void main()
{
int arr[3][3], I, j;
printf(“Enter element of array\n”);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf(“%d”,&arr[i][j]);
}
}
printf(“Enter Elements are:-\n”);
for(i=0;i<=2;i++
{
for(j=0;j<=2;j++)
{
printf(“%d”,arr[i][j]);
}
printf(“\n”);
}
}