我已经写了这个c程序用于研究目的,我发现了
printf("%s",a);
有效但printf("%s",*a);
不起作用。
我已定义a
这样的char *a[]="how are you";
为什么*a
没有指向字符串?
我收到此错误
test2.c: In function ‘main’:
test2.c:7:10: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%s \n",*a);
~^ ~~
%d
答案 0 :(得分:0)
未定义的行为因为%s
printf将*a
解释为地址,但它实际上不是地址,如果将其视为地址,则指向某个位置为您的程序读取保护。所以,你可能会遇到分段错误。