Possible Duplicate:
Does a const reference prolong the life of a temporary?
let say that I have a function f
:
int f(int x){return x;}
const int &a=f(1);
I know that f(1)
is just a temporary and i will be destroyed after this statement, but
- does making the reference const will give f(1) a long life ?
- if yes, where
f(1)
is gonna be stored ? - and is that mean that
x
also did not get destroyed when it run out of scope? - what is the difference between
f(1)
andx
?