C++ -此程序在第2行显示运行时中断错误。
char * ptr = "hello";
(*ptr)++; // should increment 'h' to 'i'
cout<<ptr<<endl; // should display 'iello'
Test.exe中0x004114b0处的未处理异常: 0xC0000005:写入位置0x00417830的访问冲突。
你知道为什么它会给出这个错误吗?然而,如果我运行下面的代码,它会工作得非常好。
char arr[] = "hello";
char * ptr = arr;
(*ptr)++; // increments 'h' to 'i'
cout<<ptr<<endl; // displays 'iello'
发布于 2011-08-16 16:10:27
发布于 2011-08-16 16:12:59
当您声明char * ptr =“hello”时,这意味着ptr指向一个常量字符串
当您说ptr++时,您正在尝试更改不正确的基地址
https://stackoverflow.com/questions/7075257
复制相似问题