I want to print out a multiplication table based on how big the user wants it to be. I also want this program to do this via functions.
Right now, the code runs, but I get a few errors:
1. "Stack around the variable 'table' was corrupted.
2. A buffer overrun has occurred in multTable.exe which has corrupted the program's internal state
Now it prints the table how i want... But I am extremely confused how to pass multidimensional arrays to functions... I understand single dimension arrays, but I am so confused going for 2D.
Passing multidimensional arrays to functions isn't all that different from normal arrays. Here is one way of doing it:
1 2 3 4 5 6 7 8
void doFunc(int** array, int height, int width) {
// do something with the array, for example:
for (int row = 0; i < height; ++row) {
for (int col = 0; i < width; ++col) {
cout << array[row][col] << '\t';
}
}
}
EDIT:
Also, for your problem with the arrays, how about you just have a 10x10 array and simply set the result of the table to be table[i][j] = (i+1) * (j+1)?
ok, so when i try to initialize the 2D array in main...
1 2 3
int row = 10;
int col = 10;
int *table = newint[row][col];
it says: Error: expression must have a constant value. Which makes sense as you have to know at least the last value. I understand this concept, I just don't know how to go from here.