-->

Learn to code the on-demand coding Languages in an easy way. We help you understand programming concepts and coding Techniques Better.

Tuesday, January 26, 2021

Associativity and Precedence

 Associativity and Precedence :



Follow the Associativity rules for calculating any expressions with more than one operator.  The Associativity Rules for Each operator are listed below. 

Category

Operator

Associativity

Postfix

()  []  ->  ++   --

Left to Right

Unary

+  -  !  ~  ++  --

Right to Left

Multiplication

*  /  %

Left to Right

Addition

+  -

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


  
Examples: 
    
    1. x = ((10+20)*5+2)
                (30*5+2)
                150+2
                152

    2. x= 10 * 2 % 10 / 2
                20%10/2
                20%5
                0

No comments:

Post a Comment