I was watching a tutorial about rvalues and lvalues and I got a little confused.
int& GetValue()
{
static int value = 5;
return value;
}
int main()
{
int a = GetValue();
GetValue() = 8;
std::cout << a << std::endl;
std::cout << GetValue() << std::endl;
int b = GetValue();
std::cout << b << std::endl;
return 0;
}
This prints
5
8
8
I don't understand how GetValue() = 8; changes the value from 5 to 8. And now I always get 8 when you call GetValue().