+ 1
How to pass 2D array to a function
i want to calculate the addition of 2 2D matrix in function called by main and return type must b 2D array
4 ответов
+ 1
you need not return a 2d array work like this....
void use2darrayfunction ( int arr [][***] )
in place of *** you have to put some numerical constant....
for example if your array was declared like this in main ()
int arr [10][25];
then call the function like this
use2darrayfunction ( arr );
and the value in the place of *** should be 25
use the array as you want and the original array will change from the function itself....
+ 1
if you want the array to be treated like an array (without losing the size property) you should do( for a a 2d array of ints ):
template <int N, int M>
void my_function(int (&arr)[N][M]) { ... }
n and m are the sizes of the array
if you dont care about having a pointer, call it like this:
void muy_function(int **arr) { ... }
0
An example:
void myfunc(int arr2d[5][30])
Returning an int** works in other compilers...
0
dude....thats wrong....