Two Dimensional Arrays in C++

Arrays and pointers have a close relationship. As we will soon see, an array in C++, is basically a constant pointer.

Passing Double Arrays two Functions

void printOut2D(int x[][COLS], int rows){
 

    }

}

Pointers and Double Arrays

Download the code below and run it. WHen you create a pointer two a double array of ints with 3 rows and 4 columns you're really creating a pointer to an array of 4 ints (number of columns)
const int ROWS =3;
    const int COLS = 4;
// create the douible array
int matrix[ROWS][COLS];


int i,j;
for(i =0;i< ROWS; i++)
    for(j= 0;j<COLS; j++)
    matrix[i][j] = rand() % 100;


//a pointer to COLS number of ints
// if COLS is 4 this is a pointer to
// an array of 4 ints
int (*ptr)[COLS] = matrix;


for(int i =0;i< ROWS; i++){
    for(int j= 0;j<COLS; j++)
        cout<<ptr[i][j] << " ";
        cout<<endl;
}