我不明白,不是说 ++a 的意思是先自加 1 再运算吗,这个没什么疑问;那么同理:--a 不就应该是 a 先自减 1 再运算吗?但问题来了,为什么实际情况不是这样的?下面是代码与运算结果,求解惑!!!【代码】#include <iostream>
using namespace std;
int main()
{
int a=20, b=10, c;
cout << "a = " << a << endl << "b = " << b << endl << endl;
c = a + b;
cout << "c = a+b = " << c << endl;
c = a - b;
cout << "c = a-b = " << c << endl;
c = a * b;
cout << "c = a*b = " << c << endl;
c = a / b;
cout << "c = a/b = " << c << endl;
c = a % b;
cout << "c = a%b = " << c << endl;
c = ++a;
cout << "c = ++a = " << c << endl;
//cout << "说明:++a 是先自加 1 再把 a 赋值给 c!" << endl;
c = --a;
cout << "c = --a = " << c << endl;
//cout << "说明:--a 是先自减 1 再把 a 赋值给 c!" << endl;
return 0;
}【运算结果】a = 20
b = 10
c = a+b = 30
c = a-b = 10
c = a*b = 200
c = a/b = 2
c = a%b = 0
c = ++a = 21
c = --a = 20
请按任意键继续. . .
- 2 回答
- 0 关注
- 1657 浏览
添加回答
举报
0/150
提交
取消