指针变量,指针数组赋值初始化错误
VS2017调试时,出现如下报错代码:
E0144 "const char *" 类型的值不能用于初始化 "char *" 类型的实体
可能原因,字符串const,不能直接给指针赋值
char *point[]= { "one","two","three","four" };
char *name="zhang";
解决方案:
(1)可将字符先使用字符数组存储,在使用指针;
char nameone[]="zhang";
char *name=nameone;
(2)在前面加上 const
const char *point[]= { "one","two","three","four" };

如果想要输出第二行的字符串,有两种方法:
(1)printf("%s\n", (point+2));
(2)while (point[2]!='\0')
{
printf("%c", *point[2]++);
}
注意两种指针的格式符
浙公网安备 33010602011771号