C++ で、コンパイラが次の文字ポインタを次のように変更できない理由
#include <iostream>
int main()
{
char* cp = "overflow";
cp[1]='p';
return 0;
}
出力 : 実行時にクラッシュします。
ただし、文字配列は許可されますが、
#include <iostream>
int main()
{
char cps[] = "overflow";
cp[1]='p'; // this compiles fine and output is operflow
return 0;
}
実行時に何が起こっているのか、なぜクラッシュしているのかを知りたいだけです。ありがとうございました。