How to pass a two-dimensional array to a function in C?

前端 未结 3 1344
时光说笑
时光说笑 2021-01-15 07:59

My function prototype is

int** rotate(int **arr, int row, int col, int fl);

where arr is the two dimensional array, row<

3条回答
  •  再見小時候
    2021-01-15 08:40

    A pointer to a pointer is different from a pointer to an array. Array-to-pointer decaying can only happen on the left-most side (e.g. int [3][20] to int (*)[20]).

    Change your function declaration to

    int** rotate(int (*arr)[20], int row, int col, int fl);
    

    or more obviously,

    int** rotate(int arr[][20], int row, int col, int fl);
    

    Note you have to fix the size at compile-time.

提交回复
热议问题