1

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;
}

krish
  • 43
  • 4
  • See [Passing a 2D array to a C++ function](https://stackoverflow.com/questions/8767166/passing-a-2d-array-to-a-c-function). – Jason Nov 05 '22 at 06:37

0 Answers0