28
29 // function to output array with two rows and three
columns
30 void printArray( int a[][ 3 ] )
31 {
32 for ( int i = 0; i < 2; i++ ) { // for each
row
33
34 for ( int j = 0; j < 3; j++ ) // output column values
35 cout
<< a[ i ][ j ] << ' ';
36
37 cout
<< endl; // start new line of
output
38
39 } // end outer for
structure
40
41 } // end function printArray
Values in array1 by row
are:
1 2 3
4 5 6
Values in array2 by row
are:
1 2 3
4 5 0
Values in array3 by row
are:
1 2 0
4 0 0
For loops are often used to iterate through arrays. Nested loops are helpful with multiple-subscripted arrays.