Possible Duplicate:
Can a local variable's memory be accessed outside its scope?
When Automatic Memory Deallocated ?
void fun3(int a){
a = 5;
}
Does ‘a’ deallocated when the function end ?
Yes !
So What is the reason for this output ?
http://ideone.com/2ZJ57
Yes
ais deallocated when the scope of the function ends.So What is the reason for this output ?
Accessing the contents of an automatic variable through an pointer to the memory location beyond the scope in which the variable exists is an Undefined Behavior as per the standard.
Your program does exactly that, so it has an Undefined Behavior(UB). With UB your program can show any behavior valid or invalidRef 1.
Ref 1C++03 section 1.3.24: