- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Core Dump (Segmentation fault) in C/C++
In this tutorial, we will be discussing a program to understand core dump (segmentation fault) in C/C++.
It happens due to reasons like when code tries to write on read only memory or tries to access corrupt memory location.
Example
Modifying a string literal
int main(){ char *str; str = "GfG"; *(str+1) = 'n'; return 0; }
Accessing out of array index bounds
#include <iostream> using namespace std; int main(){ int arr[2]; arr[3] = 10; return 0; }
Accessing an address which is freed
#include <stdio.h> #include<alloc.h> int main(void){ int* p = malloc(8); *p = 100; free(p); *p = 110; return 0; }
Output
Abnormal termination of program
Advertisements