Technically, the memory where a
was stored is available for us by other contexts, so to answer your question, yes.
This depends on some factors though. There might not even be memory to speak of. In your particular example, the optimizer might just cut everything out. Even if you do something like cout << a
, a 5
might be inlined which doesn't reside in memory.
Note that if you pass by reference, the lifetime is that of the original variable.
Also, just because it's deallocated that doesn't mean the memory is automatically cleaned afterwards. The value might still reside there until that memory is reused.
Your example exibits undefined behavior:
void fun3(int *&p, int a){
p = &a;
}
a
is a local variable, and you take its address and assign it to p
, which you then use outside the function. Anything can happen.