Passing 2-D array as argument

You should at least specify the size of your second dimension.

int array[][5] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8, 9 }, { 10, 11, 12, 13 } };

There is also an error which is often repeated. To pass a 2D array as argument, you have to use the following types:

void myFuntion(int (*array)[SIZE2]);
/* or */
void myFuntion(int array[SIZE1][SIZE2]);

Why don't use std::vector instead of "raw" arrays. Advantages:
1. It can dynamically grow.
2. There is no issues about passing arguments to the function. I.e. try to call void myFuntion(int array[SIZE1][SIZE2]); with array, that has some different sizes not SIZE1 and SIZE2


  void myFunction(int arr[][4])

you can put any number in the first [] but the compiler will ignore it. When passing a vector as parameter you must specify all dimensions but the first one.

Tags:

C++

Pointers