我的函数原型是
int** rotate(int **arr, int row, int col, int fl);其中,arr是二维数组,row和col分别是2D数组的行数和列数,fl是标志变量.如果fl的值是0,则该数组将向右旋转;如果fl是1,则该数组将向左旋转.
where arr is the two dimensional array, row and col is the number of row and columns of the 2D array respectively, fl is a flag variable. If the value of fl is 0 then the array will be rotated right, if fl is 1 then the array will be rotated left.
我调用了以下函数:
int **res= rotate(arr, row, col, fl);但是我得到一个警告和一个音符
But I got one warning and one note
[Warning] passing argument 1 of 'rotate' from incompatible pointer type. [Note] expected 'int **' but argument is of type 'int (*)[20]'推荐答案
指向指针的指针与指向数组的指针不同.数组到指针的衰减只能发生在最左侧(例如int [3][20]至int (*)[20]).
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]).
将函数声明更改为
int** rotate(int (*arr)[20], int row, int col, int fl);或更明显的是
int** rotate(int arr[][20], int row, int col, int fl);请注意,您必须在编译时固定大小.
Note you have to fix the size at compile-time.
更多推荐
如何将二维数组传递给C中的函数?
发布评论