GOOC - Game Oriented Object C

GOOC - Game Oriented Object C

Previous: Other Operators, Up: Expressions and Operators
[Contents]

7.13. Operator Precedence

7.13. Operator Precedence

When an expression contains multiple operators, such as a + b * c >> 8, the operators are grouped based on rules of precedence. For instance, the meaning of that expression is to multiply b by c, right shift the result by 8, then add that result to a. The rules of operator precedence determine the order of this expression.

The following is a list of types of expressions, presented in order of highest precedence first. Sometimes two or more operators have equal precedence; all those operators are applied from left to right unless stated otherwise.

  1. Operators with operands enclosed in separators such as parenthesis, and field access operator ->.
  2. Unary operators: +, -, !, ~, &.
  3. Multiplication, division, and modular division: *, /, %.
  4. Addition and subtraction expressions: +, -. These expressions are evaluated right-to-left.
  5. Bitwise shifting expressions: <<, >>.
  6. Greater-than, less-than, greater-than-or-equal-to, and less-than-or-equal-to expressions: >, <, >=, <=.
  7. Equal-to and not-equal-to expressions: ==, !=.
  8. Bitwise TEST expressions: \.
  9. Bitwise AND expressions: &.
  10. Bitwise XOR expressions: ^.
  11. Bitwise OR expressions: |.
  12. Logical AND expressions: &&. These expressions are evaluated right-to-left.
  13. Logical OR expressions: ||. These expressions are evaluated right-to-left.
  14. Conditional expressions: ?:.