Moh*_*ain -2 c++ reference function
代码的输出是30。但是我不确定它是如何实现的。
#include <iostream>
int &fun()
{
static int x = 10;
return x;
}
int main()
{
fun() = 30;
std::cout << fun();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期望输出为10,但显示为30。如何?