void myPrint (int **vect, int row, int col) { int (*p)[2]=(int(*)[2]) vect; for (int i=0; i<row; i++) for (int j=0; j<col; j++) printf("%d\n",p[i][j]); }
int main(int argc, const char * argv[]) { int a [3] [2] = {{1,2},{3,4},{5,6}} ; myPrint((int**)a, 3, 2); return 0; }
@itfanr 因为标准是这样的,某类型的数组只会转换为该类型的指针,对应二维数组只会转换为一维数组指针,int[3][2]->int(*)[2]。所以要么按内存排布自己处理,要么强转回原始类型 729 Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type “array of type” is converted to an expression with type “pointer to type” that points to the initial element of the array object and is not an lvalue. http://c0x.coding-guidelines.com/6.3.2.1.html