Page 302 - Web Applications (803) Class 11
P. 302

Output of the above code is as follows:
















                 4.11 ASSOCIATIVITY AND OPERATOR PRECEDENCE
              When an expression contains a large number of operators and operands and the sequence of evaluations is uncertain,
              operator precedence and associative rules come into play.

              Operator Precedence

              Operator precedence refers to how the operator interacts with its operand. It determines which operation takes
              precedence over the others. The hierarchy of precedence operators is established, with the operator with the highest
              precedence standing at the top. For example, because the multiplication operator takes precedence over the addition
              operator, the multiplication operation is executed before the addition operation in an expression.

              Operator Associativity

              The order in which an operator evaluates its operand, i.e. from left to right or right to left. When two operators have
              equal precedence in an expression, the association is generally left to right.

                             Precedence           Type                 Operators             Associativity
                                  1        Postfix            () [] ->. ++--                 Left to right

                                  2        Unary              +-!~++--(type)* & sizeof       Right to left
                                  3        Multiplicative     */%                            Left to right
                                  4        Additive           +-                             Left to right

                                  5        Shift              <<, >>                         Left to right
                                  6        Relational         <<=>>=                         Left to right
                                  7        Equality           ==!=                           Left to right
                                  8        Bitwise AND        &                              Left to right

                                  9        Bitwise XOR        ^                              Left to right
                                 10        Bitwise OR         |                              Left to right
                                 11        Logical AND        &&                             Left to right

                                 12        Logical OR         II                             Left to right
                                 13        Conditional        ?:                             Right to left
                                 14        Assignment         =+=-=*=/=%=>>=<<=&=^=|=        Right to left
                                 15        Comma              ,                              Left to right


              Let us take some examples of operator precedence.
              Ð ÐIf var a = 8, then the output of the following expression will be:
              Ð a += ++a + a-- % --a

                300     Touchpad Web Applications-XI
   297   298   299   300   301   302   303   304   305   306   307