// Example 2-1 How is a 2D array stored in memory? #include #include using namespace std; int main() { // declare and initialize a two dimensional array int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; // print the array elements for (int row = 0; row < 3; row++) { for (int col = 0; col < 4; col ++) { cout << setw(10) << a[row][col]; } cout << endl; } cout << endl; // print the addresses of the array elements for (int row = 0; row < 3; row++) { for (int col = 0; col < 4; col ++) { cout << setw(10) << &(a[row][col]); } cout << endl; } cout << endl; // print the addresses of the array elements as decimal numbers for (int row = 0; row < 3; row++) { for (int col = 0; col < 4; col ++) { cout << setw(10) << reinterpret_cast(&(a[row][col])); } cout << endl; } cout << endl; // print the address of the array and of each row cout << "Address of a = " << &a << endl; cout << "Address of the first row = " << &a[0] << endl; cout << "Address of the second row = " << &a[1] << endl; cout << "Address of the third row = " << &a[2] << endl; }