1 // Fig. 4.22: fig04_22.cpp
2 // Initializing multidimensional arrays.
3 #include <iostream>
4
5 using std::cout;
6 using std::endl;
7
8 void printArray( int [][ 3 ] );
9
10 int main()
11 {
12 int array1[ 2 ][ 3 ] = { { 1, 2, 3 }, { 4, 5, 6 } };
13 int array2[ 2 ][ 3 ] = { 1, 2, 3, 4, 5 };
14 int array3[ 2 ][ 3 ] = { { 1, 2 }, { 4 } };
15
16 cout
<< "Values
in array1 by row are:" << endl;
17 printArray( array1 );
18
19 cout
<< "Values
in array2 by row are:" << endl;
20 printArray( array2 );
21
22 cout
<< "Values
in array3 by row are:" << endl;
23 printArray( array3 );
24
25 return 0; // indicates
successful termination
26
27 } // end main
Note the various initialization styles. The elements in array2 are assigned to the first row and then the second.
Note the format of the prototype.