c++ - Why value of local variable(its address is stored in global variable) is freed when function has completed its execution -
this code
#include<iostream> using namespace std; int *ptr; void hold(){ int a=12; ptr=&a; }; int main(){ hold(); cout<<"value of a="<<*ptr; };
and value of a=12
must not happen because compiler has freed value @ address of why 12 comes?
freeing doesn't mean system modify value stored there (which involve unnecessary overhead). means memory space made available future storage.
Comments
Post a Comment