I need to determine whether the syntax of:
int& f1(int i, int& j) { int& k = i; j+=i; return k; }
is correct.
I have tested it, and to my astonishment, it compiles.
My understanding, since our function f1 is of of type int& it cannot return local variables. By calling the function, I create a local variable i. When I set int& k = i, I am setting the memory space of k to that of i. Therefore k is a local variable and thus it should not compile, since local variable kis returned.
Any explanations are extremely helpful.