在C语言中,为什么我可以将字符数组传递给以
例如:
在第二种情况下,我会收到编译器警告:
char *
作为参数的函数,但无法将数组地址传递给以char **
作为参数的函数呢?
更新:有趣的是,将参数类型更改为char* qux[12]
并没有改变编译器的警告。例如:
#include <stdio.h>
void foo(char* qux) { puts(qux); }
void bar(char** qux) { puts(*qux); }
void baz(char* qux[12]) { puts(*qux); }
int main() {
char str[12] = "Hello there";
foo(str);
bar(&str); // Compiler warning
baz(&str); // Same compiler warning
return 0;
}
在第二种情况下,我会收到编译器警告:
warning: incompatible pointer types passing 'char (*)[12]' to
parameter of type 'char **' [-Wincompatible-pointer-types]
这里发生了什么?
*qux
的大小是多少? - e0k