Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2D array passed in function prototype [duplicate]

Tags:

c++

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.

like image 455
ruthless Avatar asked Oct 15 '25 16:10

ruthless


2 Answers

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);
like image 147
Fiddling Bits Avatar answered Oct 17 '25 04:10

Fiddling Bits


You may use this prototype:

template <int ROW, int COLUMN>
void multTable(int (&arr)[ROW][COLUMN], int maxNum);
like image 32
Jarod42 Avatar answered Oct 17 '25 06:10

Jarod42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!