In C, why is it that I'm able to pass character arrays to functions that take a char *
as an argument, but I cannot pass the address of an array to functions that take a char **
?
UPDATE: Interestingly, changing the argument type to char* qux[12]
doesn't change the compiler warning at all
For example:
#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;
}
In the second case, I get a compiler warning:
warning: incompatible pointer types passing 'char (*)[12]' to
parameter of type 'char **' [-Wincompatible-pointer-types]
What's going on here?