Consider the following program:
#include <iostream>
int const * f(int const &i)
{
return &i;
}
int main()
{
std::cout << f(42); // #1
std::cout << f(42); // #2
std::cout << f(42) << f(42); // #3
}
Depending on the compiler, and optimization level that is set, the addresses printed on lines #1 and #2 may or may not be different from one another.
However, regardless of choice of compiler, or optimization levels, the 2 addresses printed on line #3 are always different from one another.
Here's a demo to play around with.
So what are the rules for what f returns in each of these cases?