I am puzzled why this one is right. The return value is reference type int&,
but the the h() function return a value int type in sentence return x. So, how does the int return change to a int &?
This is the code snippet and compiles fine with the C++ compiler.
int& h() {
int q;
static int x;
return x;
}
This returns a reference to a static
int. Thexis initialized the first time the functionhis called. Use it like this:The variable
qshould have no effect and I would consider it dubious.