Consider:
int & foo () {
int b = 2;
return b;
}
int main() {
int a = foo();
std::cout << "a: " << a << std::endl;
}
Foo returns reference to variable b, which is out of scope of main. The cout prints 2. Does this mean that a copy of b is created? Or is it that lifetime of b is extended to the lifetime of a?