Go: Operator precedence
Unary operators
Unary operators have the highest precedence and bind the strongest.
Binary operators
| Prio | Operators |
|---|---|
| 1 | * / % << >> & &^ |
| 2 | + - | ^ |
| 3 | == != < <= > >= |
| 4 | && |
| 5 | || |
Among binary operators multiplication operators bind strongest, followed by addition operators, comparison operators, && (logical and), and finally || (logical or).
Binary operators of the same precedence associate from left to right:
x / y * z is the same as (x / y) * z.
Statement operators
The ++ and -- operators form statements and fall outside the operator hierarchy:
*p++ is the same as (*p)++.
Examples
^a >> bis the same as(^a) >> b1 + 2*a[i]is the same as1 + (2*a[i])m == n+1 && <-ch > 0is the same as(m == (n+1)) && ((<-ch) > 0)
Comments
Be the first to comment!