该语法还知道运算符优先级。
为什么语言运算符优先级吗?
创建前面示例中这样的复杂表达式要求彻底理解运算符优先级的规则。
Creating complex expressions such as the one in the preceding example requires a thorough understanding of the rules of operator precedence.
不幸的是,多数代码格式化工具都会漠视运算符优先级,从头到尾采用同样的空格方式。
Unfortunately, most tools for reformatting code are blind to the precedence of operators and impose the same spacing throughout.
乘法和除法运算符(表3中列出的前四个)具有高于加法和减法的优先级。
The multiplication and division operators (the first four listed in Table 3) have higher precedence than the addition and subtraction operators.
逻辑运算符的实际优先级就是表2中罗列这些运算符的顺序。
The actual precedence of the logical operators is given by the order these operators are presented in Table 2.
如果松绑定(looser - binding)运算符使用紧绑定(tighter - binding)运算符作为操作数表达式,那么优先级是自动处理的。
If looser-binding operators take as operands expressions using tighter-binding operators, precedence is handled automatically.
表达式可能会包含不止一个运算符,这些不同的运算先后次序就是运算符的优先级。
When an expression contains more than one operator, the order of evaluation depends on the order of operations.
本章末尾的表2-1完整总结了所有运算符的优先级和结合律。
Table 2.1 at the end of this chapter summarizes precedence and associativity for all operators.
有一些运算符的优先级不合适;语法的一些部分还可以做得更好。
Some of the operators have the wrong precedence; some parts of the syntax could be better.
结合性规定了具有相同优先级的运算符如何进行分组。
Associativity specifies how to group operators at the same precedence level.
幂运算符比在操作数左边的一元运算符有更高的优先级;但比右面的一元运算符要低。句法为。
The power operator binds more tightly than unary operators on its left; it binds less tightly than unary operators on its right. The syntax is.
条件运算符的优先级比按位运算符的优先级低。
The conditional operator has lower precedence than bitwise operators.
条件运算符的优先级比按位运算符的优先级低。
The conditional operator has lower precedence than bitwise operators.
应用推荐