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 生日广州男生祝福语简短