
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- What is a segmentation fault in C/C++?
- Is segmentation fault actual undefined behavior in C++?
- What is a segmentation fault in C/C++ program?
- List of Common Reasons for Segmentation Faults in C/C++
- How to find Segmentation Error in C & C++ ? (Using GDB)
- What is Byzantine Fault Tolerance?
- Dump Multi-Dimensional arrays in Java
- What is Segmentation?
- Fashion Consumer Segmentation
- How to debug a core in C/C++?
- What is routing in C# ASP.NET Core?
- What is Metapackage in C# Asp.net Core?
- What is Market Segmentation?
- Dump the content of an array in Java
- How to enable Session in C# ASP.NET Core?

Advertisements