I am new to C++, have trying hands with it. Today i was going through dynamic memory allocation. According to following link:
http://msdn.microsoft.com/en-us/library/h6227113.aspx
"Using the delete operator on an object deallocates its memory. A program that dereferences a pointer after the object is deleted can have unpredictable results or crash."
But in following example, even after using delete, when i try to print the contain of that location it prints the correct value? How?
I am really confused ....please guide me? Thank you.
int main()
{
int max_Value = 12;
int *arr = new int [max_Value];
arr[4] = 9;
cout<< "arr of four is having: "<<arr[4]<<endl;
delete[]arr;
int i = 0;
for(i=0; i<12; i++)
cout<< arr[i]<<endl;
return 0;
}