注册 登录
编程论坛 C++教室

怎么解释这样的表达式

andrew28 发布于 2008-08-15 11:18, 699 次点击
    int a = 3, b = 5;
    int s;
    s= a++ + ++b + --a;
4 回复
#2
hhitjsj0212008-08-15 11:36
3+6+2 =11?
#3
jhm8612008-08-15 11:47
是啊,其中a++是先算a,++a是a=a+1,--a是a=a-1呀。
我运行了,结果也是这样的。有其他情况,可以一起探讨一下哦。
#4
妍清舞2008-08-15 12:11
优先级:[bo]++[/bo]/[bo]--[/bo] [bo]>[/bo] [bo]+[/bo]/[bo]-[/bo]
赋值运算符[bo]结合方向[/bo]:[bo]自右向左[/bo]
s = [bo](a++) [/bo]+ [bo](++b)[/bo] + [bo](--a)[/bo] = 3 + 6 + 2 = 11

[[it] 本帖最后由 妍清舞 于 2008-8-15 12:15 编辑 [/it]]
#5
很远的那颗星2008-08-15 12:30
undefined!!!

Repeat ++, --, on the same expression more than once is undefined...
1