Associativity defines the concept where operators occur in an expression with the same precedence. For example, in expression a + b − c, both + and – have the same precedence, then the associativity of such operators determines which part of the expression will be evaluated first. Both + and − are left associative here, so the expression will be calculated as (a+b) −c.
Precedence and associativity define the order in which an expression is evaluated.Â
Sr.No | Operator | Precedence | Associativity |
1 | Exponentiation ^ | Highest | Right Associative |
2 | Multiplication ( * ) and Division ( / ) | Second Highest | Left Associative |
3 | Addition ( + ) and Subtraction ( – ) | Lowest | Left Associative |
The above table describes the default behavior of operators. The order can be modified at any stage in the expression evaluation, using parenthesis. For example  −
In x + y * z, the expression element y*z is evaluated first, with the precedence of multiplication over addition. We use parenthesis here for first evaluation of x + y, like (x+y)*z