
在本教程中,我们将讨论一个用于理解C/C++中核心转储(分段错误)的程序。
这种情况发生的原因可能是代码试图在只读内存上写入,或者试图访问损坏的内存位置。
示例
修改字符串文字
int main(){
char *str;
str = "GfG";
*(str+1) = 'n';
return 0;
}Accessing out of array index bounds
#includeusing namespace std; int main(){ int arr[2]; arr[3] = 10; return 0; }
访问已释放的地址
#include#include int main(void){ int* p = malloc(8); *p = 100; free(p); *p = 110; return 0; }
输出
Abnormal termination of program











