Arrays 217
Table 7.4 Array Elements in Matrix form
Coll Col2 Col3
Rowl x[0] [0] x[0] [1]
x[0] [2]
Row2 x[l] [0] x[l] [1]
x [l] [2]
Row3
x[2] [0] x[2] [1]
x[2] [2]
The arrangement of array elements shown in the above Table 7.4 is only for the sake of understanding.
Conceptually the elements are shown in matrix form. Physically array elements are stored in one
continous form in the memory.
The two-dimensional array is a collection of a number of one-dimensional arrays, which are placed
one after another. For example in the above table each row of a two dimensional array can be thought
of as a single-dimensional array.
7.23 Write a program to display two-dimensional array elements together with their
addresses.
# Include <stdio.h>
# include <conio.h>
void mainO
{
Int i,j;
int a[3][3]={{l,2,3},{4,5,6},{7,8,9}}>
clrs crO ;
printf (" Array Elements andaddresss.
");
printf (" Col-0 Col-1 Col-2
");
printf (" ===== ===== ======«">;
printf (“roivO");
for (i=0,i<3;i++)
/
for ()=0,-j<3,•]'++)
printf (" %d [%5d] ", a[i][j], &a[i][j] );
printf("nRow%d"ri+l);
printf("r ");
I
OUTPUT:
Array Elements and addresss.
Col-0 Col-1 Col-2
RowO 1 [4052] 2 [4054] 3 [4056]
Rowl 4 [4058] 5 [4060] 6 [4062]
Row2 7 [4064] 8 [4066] 9 [4068]