0

How can I count the number of rows and cols in c language after dynamic allocation?

void printMatrix(int **arr)
{
    int i,j;

    int col = (sizeof(arr)/sizeof(arr[0]));
    int row = (sizeof(arr)/sizeof(arr[0][0]));
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            printf("%d\t",arr[i][j]);
        }
        printf("\n");
    }
}

In my example I get only the matrix start pointer by **arr.

It try to run this code but it return row = 1 and col = 1 when the row = 3 and col = 2.

SimpleBeat
  • 747
  • 1
  • 10
  • 20
royb
  • 693
  • 3
  • 9
  • 20

0 Answers0