
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
Advertisements