-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-數組指針 - 消除歧義) –