In a short: you can't return and pass a 2D array in these ways. Use vectors (or array of vectors as @formerlyknownas_463035818 suggested in comments).
An array is a linear part of a memory. []
operator takes value in memory by some offset. So it's equals arr[i] == *(arr + i)
. For 2D arrays, the compiler needs to know all but one dimension so compile can use it like this: arr[i][j] == *(arr + i * N + j)
. When you pass array in function you must specify sizes of all but one (or all, you want) dimensions. I.e. void f(int a[][5]);
About returning 2D arrays. Array in C++ isn't a type, it's a special form of declaration. So returning int[][]
just doesn't make sense. You have to use some kind of wrapper (such as std::array
of std::vector
), which will copy all the data.