I'm trying to understand what's going on here;
int& FunkyStuff(int num){
int val = num * 10;
std::cout << "New value is: " << val << "\n";
return num;
}
int main(){
std::cout << FunkyStuff(10) << "\n";
return 0;
}
So, when I compile this code without the printing the value within the FunkyStuff function, the main spits out a garbage value which I expect due to the fact that the val object is destroyed once leaving the scope. However, if I just compile the program as is above, the program outputs an expected value of 100 in both cases. What's going on here behind the scenes?