Page 104 - CA_Blue( J )_Class9
P. 104

You will get the following output:            Explanation of the output:
                                                                    1.  (a>b && b>c):          4.  (a<b || b>=c):
                                                                   Ans.  (10>30 && 30>25)      Ans.  (10<30 || 30>=25)
                                                                       (false && true)            (true && true)
                                                                       false                       true
                                                                    2.  (a<b && b>=c):         5.  !((a+b)>c):
                                                                    Ans.  (10<30 && 30>=25)    Ans.  !((10+30)>25)
                                                                       (true && true)             !(40>25)
                                                                        true
                                                                                                   false
                                                                    3.  (a>b || b>c):          6.  !(c>a && a<b):
                                                                     Ans.  (10>30 || 30>25)
                                                                       (false || true)         Ans.  !(25>10 && 10<30)
                                                                       true                       !(true && true)
                                                                                                   !(true)
                                                                                                   false
                  5.3.6 Assignment Operators
                  Assignment operators are used to assign values to the operands. One of the commonly used assignment
                  operators is = (equal to). It assigns a value to the operand on the left side of the operator from the right of
                  the operator.  For example, int a = 15, here a is memory space in that contains the value 15.

                  Shorthand Operator
                  Shorthand operator provides a short way to assign an expression to a variable. That is why it is also known as
                  shorthand operation. They combine an operation with assignment, making the code shorter and easier to read.
                  Shorthand operators can be used with arithmetic, bitwise, and other types of operations, and they are also known
                  as compound assignment operators. It is also used to represent  a counter or accumulator. For example:
                         int a = 15;

                         a = a + 20;
                  Using shorthand operator, can be written as:  a+= 20

                  Some other expressions that can be used as shorthand operators are:
                                            Arithmetic Expression     Use of Shorthand Operator
                                                 a = a - b                     a -= b
                                                 a = a + b                     a += b
                                                 a = a / b                     a /= b
                                                 a = a % b                     a %= b
                                                 a = a * b                     a *= b


                  5.3.7 Conditional Operator
                  Ternary operator is also known as ternary operator. The result of the expression with conditional operator depends
                  on the logical expression. If the logical expression evaluates to true then the True part will execute otherwise the
                  False part will execute. Syntax of Conditional Operator:

                  variable = (logical expression)? True part:  False part;
                  For example:
                  double var1 = 24.9;
                  double var2 = 20.9;
                  res=(var1>var2)? (var1+var2) :(var1-var2)
                  Result: 45.8
                  Explanation: Since var1>var2, the first operation is performed so, res = var1 + var2 = 45.8


                   102    Touchpad Computer Applications-IX
   99   100   101   102   103   104   105   106   107   108   109