
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Why accessing an array out of bounds does not give any error in C++?
This is due to the fact that C++ does not do bounds checking. Languages like Java and python have bounds checking so if you try to access an out of bounds element, they throw an error. C++ design principle was that it shouldn't be slower than the equivalent C code, and C doesn't do array bounds checking.
So if you try to access this out of bounds memory, the behavior of your program is undefined as this is written in the C++ standard. In general, whenever you encounter undefined behavior, anything might happen. The application may crash, it may freeze, it may run fine(or at least appear to run fine), it may interfere with other applications(not really on modern operating systems), etc.
- Related Articles
- Accessing array out of bounds in C/C++
- What is out of bounds index in an array - C language?
- How to capture out of array index out of bounds exception in Java?
- How to handle Java Array Index Out of Bounds Exception?
- Why does our urine does not have any blood cell?
- Why does comparing types in MySQL won’t raise an error?
- Why does -r option (relocatable) make ld not find any libraries
- Why does the following error occur in MySQL: ERROR 1062 (23000): Duplicate entry?
- Elements of an array that are not divisible by any element of another array in C++
- Accessing an array returned by a function in JavaScript
- (a) Why do acids not show acidic behaviour in the absence of water?(b) Why does an aqueous solution of an acid conduct electricity?(c) Why does distilled water not conduct electricity whereas rain water does?
- Get bounds of a C# three-dimensional array
- Accessing Array Elements in Perl
- Why can we not see an image in an old and worn out stainless steel plate?
- A sharp point of a pencil shine while an eraser does not. why?

Advertisements