### Passing 2D Array to function

I'm trying to pass my 2D array matrix[][] to the function findnorm() but I don't know how to set up the parameters.

 ``12345678910111213141516171819202122`` ``````#include using namespace std; const int ROWCAP = 100; const int COLCAP = 100; int findnorm(int matrix[][], int i, int j); int main() { int i, j; int matrix[ROWCAP][COLCAP]; for (i = 0; i < ROWCAP; i++) for (j = 0; j < COLCAP; j++) cin >> matrix[i][j]; } int findnorm(int matrix[][], int i, int j) { }``````
Last edited on
When passing a multi-dimensional array to a function, only the first dimension may be omitted.
 ``12345678910111213141516171819202122232425`` ``````#include using namespace std; const int ROWCAP = 100; const int COLCAP = 100; int findnorm(int matrix[][COLCAP], int i, int j); int main() { int i, j; int matrix[ROWCAP][COLCAP]; for (i = 0; i < ROWCAP; i++) for (j = 0; j < COLCAP; j++) cin >> matrix[i][j]; // following line example of syntax, not actual code int x = findnorm(matrix, 0, 0); } int findnorm(int matrix[][COLCAP], int i, int j) { }``````

See "Arrays as parameters"
http://www.cplusplus.com/doc/tutorial/arrays/
Note: These two declarations are technically identical:
 ``12`` ``````int findnorm(int matrix[][COLCAP], int i, int j); int findnorm(int* matrix[COLCAP], int i, int j);``````

Seek "array decay to pointer" for more on the subject.
Topic archived. No new replies allowed.