#include <iostream>
int a(int &x) {
x = -1;
return x;
}
int main() {
int x = 5;
std::cout << a(x) << " " << x << std::endl;
}
为什么输出是“-1 5”?C++中std :: cout的奇怪行为
PS:编译器是:
的i686-苹果darwin11-LLVM-G ++ - 4.2(GCC)4.2.1(基于苹果公司建立5658)(LLVM建立2336.11.00)
PS:编译没有任何优化。
这些标准术语是功能副作用 – fayyazkl