1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
// 2-D Multiplication Table #include <iostream> using namespace std; int main() { // declare and initialize variables int rows = 0; int columns = 0; int* p_columns; int* p_rows; int** p_p_rows; p_p_rows = &p_rows; // prompt for size of 2-D array cout << "Please specify how many rows: "; cin >> rows; cout << "Please specify how many columns "; cin >> columns; cout << endl; // array of pointers p_p_rows = new int*[rows]; // make each pointer store the address of an array of integers for (int i = 0; i < rows; i++) { p_p_rows[i] = new int[columns]; } // initialize the elements of the 2-D array to zero for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { p_p_rows[i][j] = 0;; } } // Display results for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { cout << "row[" << i << "][" << j << "] = " << p_p_rows[i][j] << endl; } } cout << endl; // Check if working properly cout << "&p_p_rows = " << &p_p_rows << endl; cout << "p_p_rows = " << *p_p_rows << endl; cout << "&p_rows = " << &p_rows << endl; // cout << "p_row = " << p_row << endl; for (int i = 0; i < rows; i++) { cout << "&p_p_rows[" << i << "] = " << &p_p_rows << endl; } }
Please specify how many rows: 2 Please specify how many columns 2 row[0][0] = 0 row[0][1] = 0 row[1][0] = 0 row[1][1] = 0 &p_p_rows = 0036FA24 p_p_rows = 007569D0 &p_rows = 0036FA30 &p_p_rows[0] = 0036FA24 &p_p_rows[1] = 0036FA24 Press any key to continue . . .
p_p_rows=new int* [rows]
<<&p_p_rows[i]<<endl;
p_p_rows = &p_rows;