C / C ++中的核心转储(分段错误)
在本教程中,我们将讨论一个程序,以了解C/C++中的核心转储(分段错误)。
发生这种情况的原因是,例如代码尝试在只读存储器上进行写操作或尝试访问损坏的存储器位置。
示例
修改字符串文字
int main(){
char *str;
str = "GfG";
*(str+1) = 'n';
return 0;
}访问数组索引范围之外
#include <iostream>
using namespace std;
int main(){
int arr[2];
arr[3] = 10;
return 0;
}访问已释放的地址
#include <stdio.h>
#include<alloc.h>
int main(void){
int* p = malloc(8);
*p = 100;
free(p);
*p = 110;
return 0;
}输出结果
Abnormal termination of program
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短