3

Possible Duplicate:
C++ calling delete on variable allocated on the stack

int i = 10;
int* iP = &i;
delete iP;

What exactly happens when this code is executed? I am not getting any runtime errors or compiler warnings at all, the pointer still holds the same address before and after calling delete on it, however after delete trying to dereference or even cast it to int crashes the program sometimes but other time it just works, which kind of smells like undefined behavior.

Community
  • 1
  • 1
dtech
  • 47,916
  • 17
  • 112
  • 190

0 Answers0