Local variable still exists after function returns
问题 I thought that once a function returns, all the local variables declared within (barring those with static keyword) are garbage collected. But when I am trying out the following code, it still prints the value after the function has returned. Can anybody explain why? int *fun(); main() { int *p; p = fun(); printf("%d",*p); //shouldn't print 5, for the variable no longer exists at this address } int *fun() { int q; q = 5; return(&q); } 回答1: If you really want it to loose the value, perhaps