运算符优先级 [英] operator precedence

查看:96
本文介绍了运算符优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于int a = 5,为什么a ++ * ++ a = 36因为*从左到右行为而++ a pre -increments a所以我们应该有5x7 = 35。我的书都说++优先于*。

For int a=5, why does a++ * ++a = 36 because * acts left-to-right and ++a pre-increments a so we should have 5x7=35. My books all say that ++ has precedence over *.

推荐答案


对于int a = 5,为什么是++ * ++ a = 36因为*从左到右,++ a pre - 增加a,所以我们应该有5x7 = 35。我的书都说++优先于*。
For int a=5, why does a++ * ++a = 36 because * acts left-to-right and ++a pre-increments a so we should have 5x7=35. My books all say that ++ has precedence over *.



我不完全确定,但是++只会在语句结束后递增,而++ a会在语句之前递增a。


所以,既然我们在声明中有++ a,a = 6

所以a ++ * ++ a = 36


并在该语句之后,a = 7.

I''m not entirely sure, but a++ will only increment after the end of the statement, while ++a will increment a before the statement.

So, since we have ++a in the statement, a = 6

so a++ * ++a = 36

and after that statement, a = 7.


读取: C-FAQ 。这是一个不确定的表达。


Sickofant,你的解释是不正确的。后增量并不意味着在声明之后。
Read: C-FAQ. It''s an undefined expression.

Sickofant, your explanation is incorrect. The postincrement does not mean after the statement.


在表达式中多次修改可修改的左手值(*)会导致

''未定义的行为' '正如标准所定义的,所以讨论上述表达式的结果将是或应该是无用的。评估

甚至可以让守护进程从你的鼻子里飞出来:它是未定义的。


亲切的问候,


Jos


(*)实际文本定义了''序列点'';在达到该序列点之前,lhv最多只能更改一次。
Altering a modifiable left-hand value in an expression more than once (*) causes
''undefined behaviour'' as defined by the Standard, so discussing what the
outcome of the expression above will or should be is useless. Evaluating
that thing can even make daemons fly out of your nose: it is undefined.

kind regards,

Jos

(*) the actual text defines a ''sequence point''; an lhv may only be altered at most
once before that sequence point is reached.


这篇关于运算符优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆