用*写的时,c中的字符串poniter不起作用

时间:2017-07-20 10:47:45

标签: c arrays string pointers

我已经写了这个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

1 个答案:

答案 0 :(得分:0)

未定义的行为因为%s printf将*a解释为地址,但它实际上不是地址,如果将其视为地址,则指向某个位置为您的程序读取保护。所以,你可能会遇到分段错误。