Sunday, 5 December 2010

precedence of operators in C.

Write the precedence of operators in C.
Ans:

      Operators                         
      Priority
     Evaluation
     ( ), !,                                      
         1st Priority
       Left to right
      *,,%,/,&&
       2nd Priority
      Left to right
       +,-,!!
      3rd Priority
     Left to right
      >,<,>=,<=,==,!=
       4th Priority
     Left to right
       =,+=,-=,*=,÷=,/=,%=
      5th Priority
     Right to left



What is meant by operator precedence and assosiativity of an operator?
Ans:
    For operators, associativity means that when the same operator appears in a row, then to which direction the evaluation binds to. In the following, 
Usually + and - have the same precedence. Consider the expression 7 − 4 + 2. The result could be either (7 − 4) + 2 = 5 or 7 − (4 + 2) = 1. The former result corresponds to the case when + and  are left-associative, the latter to when + and - are right-associative.

No comments:

Post a Comment