Deepika, Asst. Professor, Dept. of CS and E, PESCE, Mandya
25
{b1,b2,b3,……,bn},
{c1,c2,c3,………..,cn},
-------------------------
{z1,z2,z3,…………,zn}};
Example:
int a[2][2]={{1,2},
{3,4}};
How it will be stored in the memory as given below
0 1
1 2
3 4
int a[3][4]={{10,20,30,40},
{50,60,70,80},
{90,100,110,120}};
0 1 2 3
10 20 30 40
50 60 70 80
90 100 110 120
Different ways of initializing 2D array
1. Initializing all specified memory location
2. Partial array initialization
Initializing all specified memory locations
Example:
int a[3][4]={{5,20,3,4},
{50,60,90,80},
{1, 2, 7, 8} } ;
Row 0
Row 1
Row 0
Row 1
Row 2