Below is the program where I have created a array of integers that is statically sized to hold five elements. I assigned a value 4 to index 7 of the same array, which is out-of-bounds. Neither the compiler nor runtime show any errors, instead giving me the answer 4.
#include<iostream>
int main()
{
int ptr[5]={2,4,5,6,7};
ptr[7]=4;
std::cout<<ptr[7];
return 0;
}
I am using g++ version 4.7.2