- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Is segmentation fault actual undefined behavior in C++?
Undefined behavior is a way to give freedom to implementors (e.g. of compilers or of OSes) and to computers to do whatever they "want", in other words, to not care about consequences.
The cases in which segmentation fault occurs are transient in nature. They won't always result in a segmentation fault but can also run correctly(or at least appear to). For example, consider the following code fragment −
#include<iostream> int main() { int arr[2]; arr[0] = 0; arr[1] = 1; arr[2] = 2; // Undefined behaviour arr[3] = 3; // Undefined behaviour }
This code might run correctly or result in a segmentation fault. It is not really defined and implementation-dependent. You can read more about undefined behavior here − http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
- Related Articles
- What is a segmentation fault in C/C++?
- Core Dump (Segmentation fault) in C/C++
- What is a segmentation fault in C/C++ program?
- Difference between undefined, unspecified, and implementation-defined behavior in C and C++?
- What is Segmentation?
- What is Byzantine Fault Tolerance?
- What is Market Segmentation?
- Undefined Behaviour in C and C++
- Common undefined behaviours in C++ programming
- List of Common Reasons for Segmentation Faults in C/C++
- How to find Segmentation Error in C & C++ ? (Using GDB)
- What is Behavior Monitoring in Cybersecurity?
- What is Undefined X1 in JavaScript
- Default virtual behavior in C++ vs Java
- Fashion Consumer Segmentation

Advertisements