Page 166 - Computer science 868 Class 12
P. 166

It can be applied before or after the operand. Thus, they are further of two types which are given as follows:
                    Unary prefix increment operator: This operator is used to increase the value of the variable before the execution
                    starts. It is applied before the operand. This operator works on the principle of “CHANGE BEFORE EXECUTION”.
                    For example: int a = 5, b;
                                b = ++a;
                                System.out.println(a+ " : " + b);
                    Output: 6 : 6



                      Note:  The value of a is increased first, then the increased value is stored in the variable b.


                      Unary postfix increment operator: This operator is used to increase the value of the variable after the execution
                    starts. It is applied after the operand. This operator works on the principle of “CHANGE AFTER EXECUTION”.
                    For example: int a = 5, b;

                                b = a++;
                                System.out.println(a+ " : " + b);
                    Output: 6 : 5


                      Note:  The value of a is stored in the variable b, then value of a is increased by 1.



              •  Unary (--) Operator: This operator decreases the value of the variable by 1. It is also known as the decrement
                 operator.
                For example:  If a = 5, then --a = 4
                It can be applied before or after the operand. Thus, they are further of two types which are given as follows:
                    Unary prefix decrement operator: This operator is used to increase the value of the variable before the execution
                    starts. It is applied before the operand. This operator works on the principle of “CHANGE BEFORE EXECUTION”.
                    For example: int a = 5, b;
                                b = --a;
                                System.out.println(a+ " : " + b);
                    Output: 4 : 4



                      Note:  The value of a is decreased first, then the decreased value is stored in the variable b.


                     Unary postfix decrement operator: This operator is used to decrease the value of the variable after the execution
                    starts. It is applied after the operand. This operator works on the principle of “CHANGE AFTER EXECUTION”.
                    For example: int a = 5, b;
                                b = a--;

                                System.out.println(a+ " : " + b);
                    Output: 4 : 5


                      Note:  The value of a is stored in the variable b, then value of a is decreased by 1.




                164164  Touchpad Computer Science-XII
   161   162   163   164   165   166   167   168   169   170   171