Possible Duplicate:
Can a local variable's memory be accessed outside its scope?
I have the following code in C++
int* foo()
{
    int myVar = 4;
    int* ptr = &myVar;
    return ptr;
}
int main()
{
   printf("val= %d", *foo());
   return 0;
}
The output i get is:
val = 4
So my question is since myVar is a local variable, shouldn't it be gone after the function returns? and shouldn't the pointer to it be a null pointer as well?
 
     
     
     
     
     
    