2220201979 发表于 2022-9-8 21:11:33

用指针输出字符串为什么不能是*a

#include<stdio.h>
void main()
{

        char str;
        char *a;
        printf("please input the domain name of fishc\n");
        a=&str;
        scanf("%s",a);

        printf("the domain name of fishC is :%s\n",a);

}
为什么最后一行printf("the domain name of fishC is :%s\n",a);
以字符串形式输出不能写成这样printf("the domain name of fishC is :%s\n",*a);呢?

人造人 发表于 2022-9-8 21:16:28

因为 %s 要一个地址,a是一个地址,*a是一个字符
页: [1]
查看完整版本: 用指针输出字符串为什么不能是*a