the question is; Write a program that prints out the memory addresses of each element in a two-dimensionalarray. Check to see if the values printed out make sense to you based on the way I explained it
before.
Below is the code I have done. I am having problems printing the "-" sign to keep formatting with the board when the user enter in different dimensions other than [4][4].
Code:
#include <iostream>
using namespace std;
void printTable (int x, int y) {
int **p_p_twoDimension = new int* [y];
for (int i = 0; i < y; i++) {
p_p_twoDimension[i] = new int [x];
}
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) {
cout << &p_p_twoDimension[i][j];
if (j!= x - 1) {
cout << " | ";
}
}
cout << endl;
if (i!= y - 1) {
for (int k = 0; k < (x*10)+1; ++k) {
cout << "-";
}
cout << endl;
}
}
}
void freeTable (int **p_p_twoDimension, int y) {
for (int i=0; i < y; i++) {
delete [] p_p_twoDimension;
}
}
int main()
{
int x;
int y;
cout.flush() << "Please Enter the two dimensions you require" << endl;
cin >> x >> y;
int **p_p_twoDimension;
printTable(x, y);
freeTable(p_p_twoDimension, y);
return 0;
}