Hi,
I have code as follows wherein I pass a 2D array to a function and want to receive this array with its contents tripled.
#include <iostream>
#include <cstdio>
using namespace std;
int** test2 (int arr2[][4],int mul){
for (int i=0;i<2;i++){
for(int j=0;j<4;j++){
arr2[i][j]=arr2[i][j]*mul;
}
}
return arr2;//sending back the address location
}
int main(){
// code to pass and receive a 2d array
int arr2d[][4]= {{1,2,1,1},{2,2,3,4}};
int** ptrarr2d=test2(arr2d,3);
cout << ptrarr2d[0][1] << " " << ptrarr2d[0][1]<< " "<< ptrarr2d[0][2] << " " << ptrarr2d[0][3]; // to print 1st row in arr2d
return 0;
}
The error I get is 'error: cannot convert 'int (*)[4]' to 'int**' in return'.
I was able to send and receive a 1D array using 'pass by value' but for 2D I hit this error. Please advice.