I cant find out how it's the syntax.
func(int [][] a) doesnt work... any hint?
Thanks!
Printable View
I cant find out how it's the syntax.
func(int [][] a) doesnt work... any hint?
Thanks!
For multidimensional arrays I believe you have to specify the size in the function declaration and implementation (maybe not in the declaration?).
These sum up simple arrays and multidimensional arrays:
http://www.cogs.susx.ac.uk/users/pet...ml/node26.html
http://www.cogs.susx.ac.uk/users/pet...ml/node27.html
Thanks, checking now.
If you know the size at compile time, you specify the size (although the first dimension isn't necessary). If you don't know the size, or the array is dynamically allocated, you should use a vector instead. Otherwise you'll have to pass the size as an extra function parameter and pass the array by pointer.
In C/C++, you have to put array indicies ([]) after the variable name, unlike in Java where you can put them before or after. And of course, as mentioned, all but the leftmost index must have sizes in them.Code:func(int [][] a)
> func(int [][] a) doesnt work... any hint?
Copy / paste works
If your array is
int arr[X][Y][Z];
Then the function can(*) be written as
void func ( int arr[X][Y][Z] );
And you would call it with
func( arr );
(*) Some compilers will warn you about the redundant major dimension (the left-most one), so you can easily change it to
void func ( int arr[ ][Y][Z] );
If you want to spend extra effort, you can write it like this if you want
void func ( int (*arr)[Y][Z] );
All 3 forms are equivalent.