请对我放轻松,不要开枪,因为我还是新手。
当我运行这段代码时,我完全糊涂了,终生无法弄清楚为什么:
int y = 9;
cout << "++y = " << ++y << "\n--y = " << --y << "\ny++ = " << y++ << "\ny-- = " << y-- << "\n";
cout << "y = " << y << "\n";
我得到以下结果:
y = 9
++y = 9
--y = 9
y++ = 8
y-- = 9
y = 9
而不是这些结果:
y = 9
++y = 10
--y = 9
y++ = 9
y-- = 10
y = 9
我从这段代码中得到:
int y = 9;
cout << "y = " << y << "\n";
cout << "++y = " << ++y << "\n";
cout << "--y = " << --y << "\n";
cout << "y++ = " << y++ << "\n";
cout << "y-- = " << y-- << "\n";
cout << "y = " << y << "\n";
任何人都可以用尽可能简单的语言解释第一个代码中发生了什么,以便它以这种方式打印结果吗?