4

Here is my code in c++.

void multTable(int arr[][], int maxNum);

Before the main method, I declared this function prototype and then defined it after the main method towards the bottom of my code. However, I get an error stating that multidimensional array must have bounds for all dimensions. I don't understand how I can fix this.

ruthless
  • 1,090
  • 4
  • 16
  • 36

3 Answers3

4

If your 2D arrays will have a fixed column size. You can do this:

void multTable(int arr[][MAX_COLS], int maxNum);

You'll have to call it like this:

#define MAX_ROWS (5)
#define MAX_COLS (7)

int arr[MAX_ROWS][MAX_COLS] = {...};
multTable(arr, 7);
Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46
1

You may use this prototype:

template <int ROW, int COLUMN>
void multTable(int (&arr)[ROW][COLUMN], int maxNum);
Jarod42
  • 203,559
  • 14
  • 181
  • 302
1

You have to provide the second dimension of the array. Otherwise the compiler could not dereference your pointer. That's why your compiler is generating an error

#define N 10 // just an exemple

void multTable(int arr[][N], int maxNum); // N is the 2nd dimention
rullof
  • 7,124
  • 6
  • 27
  • 36