A binary expression contains two operands separated by one operator.
Not all binary operators have the same precedence.
All binary operators have left-to-right associativity.
The order in which the operands of most binary operators are evaluated is not specified. To ensure correct results, avoid creating binary expressions that depend on the order in which the compiler evaluates the operands.
As indicated in the following descriptions, the usual arithmetic conversions are performed on the operands of most binary expressions.
The following table summarizes the operators for binary expressions:
Precedence and associativity of binary operators | |||
Rank | Right Associative? | Operator Function | Usage |
---|---|---|---|
5 |
| multiplication | expr * expr |
5 |
| division | expr / expr |
5 |
| modulo (remainder) | expr % expr |
6 |
| binary addition | expr + expr |
6 |
| binary subtraction | expr - expr |
7 |
| bitwise shift left | expr << expr |
7 |
| bitwise shift right | expr >> expr |
8 |
| less than | expr < expr |
8 |
| less than or equal to | expr <= expr |
8 |
| greater than | expr > expr |
8 |
| greater than or equal to | expr >= expr |
9 |
| equal | expr == expr |
9 |
| not equal | expr != expr |
10 |
| bitwise AND | expr & expr |
11 |
| bitwise exclusive OR | expr ^ expr |
12 |
| bitwise inclusive OR | expr | expr |
13 |
| logical AND | expr && expr |
14 |
| logical inclusive OR | expr || expr |
16 | yes | simple assignment | lvalue = expr |
16 | yes | multiply and assign | lvalue *= expr |
16 | yes | divide and assign | lvalue /= expr |
16 | yes | modulo and assign | lvalue %= expr |
16 | yes | add and assign | lvalue += expr |
16 | yes | subtract and assign | lvalue -= expr |
16 | yes | shift left and assign | lvalue <<= expr |
16 | yes | shift right and assign | lvalue >>= expr |
16 | yes | bitwise AND and assign | lvalue &= expr |
16 | yes | bitwise exclusive OR and assign | lvalue ^= expr |
16 | yes | bitwise inclusive OR and assign | lvalue |= expr |
18 |
| comma (sequencing) | expr , expr |
Related References