Using multi-dimensional arrays in functions
Now that we can declare, initialize, and access arrays of many dimensions, we are ready to create functions to manipulate them. We'll proceed as follows:
- First, let's create a function to initialize a 2D array and a function to initialize a 3D array, as follows:
void initialize2DArray( int col, int row, int array[row][col] ){ for( int j = 0 ; j < row ; j++ ) {// j : 0..(row-1) for( int i = 0 ; i < col ; i++ ) {// i : 0.. // (col-1) array[j][i] = (10*(j+1)) + (i+1); } } } void intialize3DArray( int x, int y, int z, int array[z][y][x] ){ for( int k...