I was testing the new operator in C++ as the following:
#include <iostream>
using namespace std;
int main()
{
int *Q = new int[5];
Q[0] = 0;
Q[1] = 1;
Q[2] = 2;
Q[3] = 3;
Q[4] = 4;
for (int i = 0; i < 7; i++)
{
cout << "Q[" << i << "] = " << Q[i] << endl;
}
return 0;
}
If you notice, in the for loop I am exceeding the limit of the pointer and I was expecting an stack over flow type of error; but instead of that it just printed what ever these two extra locations have.
Does any one have explanation about this ?