Operator Precedence


What is operator ?

An operator is a sign or a character which denotes some action. There are various operators, and every operator has some specific work. The operators who do the basic calculation like addition, subtraction, etc., are arithmetic operators; the operators who check the conditions are relational operators. Some are logical operators and many more. Now every operator has its precedence level. If more than one operator comes in one expression, the operation gets done according to their precedence level.

Operators with there precedence and associativity

Category Operator Associativity
Postfix () [] . -> ++ -- Left to Right
Unary Misc operators Left to Right
Multiplicative *%/ Left to Right
Additive - Left to Right
Shift << >> Left to Right
Relational < > <= >= Left to Right
Equality == != Left to Right
Bitwise AND & Left to Right
Bitwise XOR ^ Left to Right
Bitwise OR | Left to Right
Logical AND && Left to Right
Logical OR || Left to Right
Conditional ?: Right to Left
Assignment = += -= *= /= Right to Left
Comma , Left to Right

This Operator precedence method is used while converting the expressions.

There are three conversions of expressions which are,

  • Infix expression
  • Prefix expression
  • Postfix expression

These conversion methods were used while converting any expression tree in data structure.