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
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短