I am trying to transpose a matrix but I m getting this error while calling the function:argument of type "int (*)[2]" is incompatible with parameter of type "int **"
This error is occuring at : **int ans = trans(a, r, c);
#include <iostream>
using namespace std;
int **trans(int **arr, int r, int c)
{
int **transpose = 0;
int i, j;
transpose = new int *[r];
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
transpose[j][i] = arr[i][j];
}
return transpose;
}
int main()
{
int r = 3, c = 2, i, j;
int a[3][2] = {{1, 2}, {3, 4}, {5, 6}};
int **ans = trans(a, r, c);
for (i = 0; i < c; ++i)
{
for (j = 0; j < r; ++j)
cout << ans[i][j] << " ";
cout << endl;
}
return 0;
}