有一个简单的程序
#include <stdio.h>
int counter = 3;
const int& f() {
return counter++;
}
const int& g() {
return counter++;
}
const int& h(int w) {
counter = w;
return counter;
}
void main()
{
const int& x = f();
const int& y = g();
const int& z = g();
const int& t = h(123);
counter = 45678;
printf("%d %d %d %d", x, y, z, t);
}
Run Code Online (Sandbox Code Playgroud)
为什么它的输出是5 5 5 45678?特别是,为什么x和y是5?如果初始化后它们仍然连接到计数器,为什么它们不是 45679 或类似的东西?