I'm trying to experiment passing 2D arrays to a function using C++. As part of that, when I allocated the space to a 3*2 matrix, and during execution, I'm not able to figure out as to why the compiler throws "terminate called recusively".
Any help would be appreciated.
Edit: This works perfectly fine in Online compiler. (My system used a gcc compiler -> MingW on Windows)
void printMat(int **arr, int m, int n)
{
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
cout<<arr[i][j]<<" ";
}
int main()
{
int m=3, n=2;
int **arr;
arr = new int *[m];
for(int i=0; i<m; i++)
{
arr[i] = new int[n];
for(int j=0; j<m; j++)
{
arr[i][j]=i;
cout<<arr[i][j]<<" ";
}
}
cout<<"Reached"<<endl;
printMat(arr, m, n);
return 0;
}