I still don't quite understand why so many people use multidimensional arrays -- they're syntax hell.
Anyway what you're asking for in your words and what you're illustrating with code are two different things. In a sense you could say there are two types of 2D arrays:
- "real" 2D arrays in that they're simply an array that takes two indeces. IE:
int someArray[3][3];
- pointers to an array of pointers. IE: what you're illustrating with your code.
Pointers to pointers are not really 2D arrays, they're more like layered 1D arrays. Although they're indexed with the same [][] syntax.
ANYWAY, to make a function take a "pointer to a pointer" style 2D array, it's quite simple:
1 2 3 4
|
void someFunction(int** someArray)
{
someArray[y][x] = example;
}
|
Working with "real" 2D arrays is a bit tricker because the size of all but the first brakets must be known:
1 2 3
|
void someFunc(int someArray[][3])
{
}
|
You cannot omit that [3] -- nor can you pass an array of a different size. IE:
int foo[3][4];
could not be passed to that function.
The "pointer to a pointer" approach can work with arrays of any size, though.
But note again that these types are not interchangable. If you have a pointer-to-a-pointer type you cannot pass it to a function that takes a "real" type, and vice versa.
EDIT -- fixed a dumb goof
EDIT 2:
I suppose I should mention that a better approach would be to objectify your arrays in a container class and pass a reference to that container class to a function, rather than passing an array directly.