70,034
社区成员
发帖
与我相关
我的任务
分享char *a="efgh";
char *c="abcd";
char d[]="abcd";
//strcpy(c,a);
strcpy(d,a);
//指针字符串不能作为复制后的字符串
内存分配不同
从a、c和d的值可以看出来,a和c是在一起的,在程序内存的常量区‘而d在程序内存的栈中,所以可以往d中拷贝数据,但是不能往a和c中拷贝数据char *a = "hello segment";
main.cpp:8:15: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
char *a = "hello segment";