cpp/language/operator precedence

The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.

When parsing an expression, an operator which is listed on some row of the table above with a precedence will be bound tighter (as if by parentheses) to its arguments than any operator that is listed on a row further below it with a lower precedence. For example, the expressions and   are parsed as  and, and not as  or.

Operators that have the same precedence are bound to their arguments in the direction of their associativity. For example, the expression is parsed as, and not as  because of right-to-left associativity of assignment, but  is parsed  and not  because of left-to-right associativity of addition and subtraction.

Associativity specification is redundant for unary operators and is only shown for completeness: unary prefix operators always associate right-to-left ( is ) and unary postfix operators always associate left-to-right ( is ). Note that the associativity is meaningful for member access operators, even though they are grouped with unary postfix operators: is parsed  and not.

Operator precedence is unaffected by. For example, parses as  because the precedence of arithmetic left shift is higher than the conditional operator.