Bound Checking
No checking on array bounds is performed. If an array’s length is set to 10:
int arrayOfInt[10];
the following statement is legal:
cout << arrayOfInt[16];
and it simply returns the content that the fifteenth element would have had,
had the array been declared as being of length 17 or above. Reading such
an element does no harm. Assigning some value to it can introduce some hard to
spot bug.
In order to obtain bound checking, use the
array STL template.
Example
#include <iostream>
using namespace std;
int main()
{
int arrayOfInt[10];
arrayOfInt[16] = 6;
cout << "7th int after the last array element: "
<< arrayOfInt[16];
}
Output
7th int after the last array element: 6