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

Comments

Be the first to comment!