char c[]="opop";
c[2]='k';
但它应该会报总线错误,为什么它会起作用?
最佳答案
您拥有的是一个数组,而不是字符串文字。这是完全有效的代码。
char *c="opop";
c[2]='k';
会导致未定义的行为并且很可能会导致崩溃。
好读:
What is the difference between char a[] = "string"; and char *p = "string";
关于c++ - 如果字符串是不可变的,为什么下面的代码在 turbo c++ 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10425777/