We can initialize array2D at the declaration stage in several ways, as follows:
int array2D[4][5] = {0};
array2D is initialized with all of its elements set to 0. Note that we cannot use our constant sizes to initialize the array at declaration. Try it and see what error message you get.
To give each element a different value at the declaration stage, we would initialize it as follows:
int array2D[size2D][size1D] = { {11 , 12 , 13 , 14 , 15 } ,
{21 , 22 , 23 , 24 , 25 } ,
{31 , 32 , 33 , 34 , 35 } ,
{41 , 42 , 43 , 44 , 45 ) };
In this declaration, the first row of elements is given the 11..15values, and the second row is given the 21..25values. Notice how the initialization of the array in this manner closely matches our conceptualization of a two-dimensional array earlier in this chapter.
...