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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -