int main() { char *s = "hello"; char *t = "world"; *s++ = *t++; cout<<*s<<endl; cout<<s<<endl; return 0; }
char *s = "hello";char *t = "world"; 你的hello,world存储在常量区,不能修改。不是你指针操作的问题。
char *s = "hello";char *t = "world";
char *s = "hello"; 的话, 并没有为s分配内存,它指向的是存有"hello"字符串的只读内存区
int main() { char *s = "hello"; char *t = "world"; *s++ = *t++; cout<<*s<<endl; cout<<s<<endl; return 0; } 上面一段程序编译,连接都没有问题,运行时会提示内存不能写,问题应该出现在*s++ = *t++这一行代码上,但是不知道是什么原因。字符串复制函数的原型就是这样写的,为什么没错
64,637
社区成员
250,559
社区内容
加载中
试试用AI创作助手写篇文章吧