-5
void f(int **);
void g(int *[]);
void h(int *[3]);
void i(int (*)[]);
void j(int (*)[3]);
void k(int [][3]);
void f(int **a) {}
void g(int *a[]) {}
void h(int *a[3]) {}
void i(int (*a)[]) {}
void j(int (*a)[3]) {}
void k(int a[][3]) {}
int main(void) {
int a[3] = {1,2,3};
int b[2] = {4,5};
int *c[2] = {a, b};
int d[2][3] = {{1,2,3},{4,5,6}};
f(c);
f(d); // note: expected ‘int **’ but argument is of type ‘int (*)[3]’
g(c);
g(d); // note: expected ‘int **’ but argument is of type ‘int (*)[3]’
h(c);
h(d); // note: expected ‘int **’ but argument is of type ‘int (*)[3]’
i(c); // note: expected ‘int (*)[]’ but argument is of type ‘int **’
i(d);
j(c); // note: expected ‘int (*)[3]’ but argument is of type ‘int **’
j(d);
k(c); // note: expected ‘int (*)[3]’ but argument is of type ‘int **’
k(d);
return 0;
}
这些C函数参数类型有什么区别? 指针阵列和二维数组之间存在很多混淆 注释是GCC警告日志。这些C函数参数类型有什么区别?
'int **'是指向'int'的指针。 'int(*)[3]'是指向“int”数组的指针。两者不同,不可互换。 – ameyCU
参见[cdecl.org](https://cdecl.org/?q=void+i%28int+%28*%29%5B%5D%29%3Bhttps://cdecl.org/?q=void+i %28int +%28 *%29%5B%5D%29%3B) – Garf365
[C指针指向数组/指针消除歧义指针]的可能重复(http://stackoverflow.com/questions/859634/c-pointer-to-数组指针 - 消除歧义) –