Possible Duplicate:
C++ Returning reference to local variable
Can a local variable’s memory be accessed outside its scope?
In the following code
int& h() {
int o=100;
return o;
}
int main() {
int t=h(); //line 1
cout<<t; //line 2
return 0;
}
Why the output is coming as 100 i.e. the value of the local variable of the function and why there is no error in line 1 because the return type of function is int& but we are returning its return value to a int.