이 튜토리얼에서는 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