Page 98 - CA_Blue( J )_Class9
P. 98

After the calculation of the expression, the value of m = 6 and n = 30


                                         m             ++m             *5             n = result
                                          5              6             30                30
                                                                                      m = 6
                                             After the execution of the program code
                                                                                      n = 30


                  Prefix Decrement Operator
                  The prefix decrement operator is written before the operand. First the operand’s value is decreased by 1, and then
                  it is used in the expression.
                  For example:
                         int b=5, c;
                         c=--b*b;

                  After the calculation of the expression, the value of b= 4 and c = 16

                                          b             --b            *b              c=result
                                          5              4              4                16

                                                                                      b = 4
                                             After the execution of the program code
                                                                                      c = 16

                  5.3.2 Postfix Operator
                  As the word “post” suggests, the increment or decrement calculation is executed after rest of the operations such
                  as assigning the value. Here, the operator is placed after of the operand. So, it works on the principal of “Increment
                  or Decrement after calculation”.

                  There are two types of Postfix Operators: Postfix Increment Operator and Postfix Decrement Operator

                  Postfix Increment Operator
                  The postfix increment operator is written after the operand. First the operand’s value is used in the expression,
                  and then the value is increased by one 1. For example:
                         int a=10 ,r;
                         r=a++ *4;
                  After the calculation of the expression, the value of a = 11 and r = 40


                                         a++            *4              r = result           a
                                         10             10                40                11

                                                                                      a = 11
                                             After the execution of the program code
                                                                                      r = 40



                  Postfix Decrement Operator
                  The postfix decrement operator is written after the operand. First the operand’s value is used in the expression,
                  and then the value is decreased by one 1. For example:
                         int b=5,r;
                         r=b-- *b;



                    96    Touchpad Computer Applications-IX
   93   94   95   96   97   98   99   100   101   102   103