Initialization of Two-Dimensional Arrays:
Like
one-dimensional arrays, two-dimensional arrays may be initialized at either of
following stages:
At compile time
At run time
At compile time
At run time
Compile Time Initialization:
We
can initialize the elements of two-dimensional arrays in the same way as the
one-dimensional arrays when they are declared. For Example:
int table [2][3]= {0,0,0,1,1,1};
initializes
the elements of the first row to zero and second row to one. The initialization
is done row br row.
Run Time Initialization:
A
two-dimensional array can be explicitly initialized at run time. For example,
consider the following segment of C program.
int
a[2][3];
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
}
}
Post a Comment