Possible Duplicate:
Can a local variable's memory be accessed outside its scope?
i have following question related to memory managment,source from where i am reading this article says that, When a variable goes out of scope, that memory is no longer guaranteed to store the variable’s value example code is given
int main() {
  int *p;
  if (true) {
    int x = 5;
    p = &x;
  }
cout << *p << endl; // ???
}
it says also that Here, p has become a dangling pointer (points to memory whose contents are undefined) but this code shows me result 5.so that is wrong in writing such code?please explain me
 
     
     
     
     
     
    