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 侄儿生日祝福语简短独特