Page 63 - Trackpad_ipro 4.1_Class8
P. 63

Operator              Description                 Syntax               Example           Output
                  && (AND) Returns  ‘true’  if all the  given  (a>b) && (b>c) (11 > 4) && (4 > 15)  false
                              conditions are true                                 (11 > 4) && (15 > 4) true
                    || (OR)   Returns ‘true’ if any one of the  (a>b) || (b>c)    (11 > 4) || (4 > 15)    true
                              given conditions is true                            (11 > 4) || (15 > 4)    true

                   NOT (!)    Returns ‘true’ if the condition  ! (a > b)          !(11 > 4)               false
                              returns false and vice-versa                        !(4 > 11)               true

                 Unary Operators

                 Unary operators are  special operators  that  require  only one operand  or  value to perform
                 operations. Increment and decrement are the examples of unary operators.

                                                                                     Example
                    Operator                Description               Syntax                             Output
                                                                                (int a = 11, b = 0)
                       ++
                                  Returns the incremented value         a ++          b = a++           a=12 b=11
                   (increment)

                        --
                                  Returns the decremented value         a --           b = a--          a=10 b=11
                   (decrement)
                 Assignment Operators


                 Assignment operators are  used to assign values to operands.  One  of the  most commonly
                 used assignment operators is equal (=). This operator can also be used with arithmetic operators
                 to  make shorthand  assignment operators.  The  shorthand  assignment operators  perform
                 calculations and assign the result to the variable present on the left hand side of the operator.
                                                                                         Example
                  Operator                 Description                   Syntax                            Output
                                                                                    (int a = 10, b = 2)
                             Returns  the  result to the  operand
                                                                                          a += b            a = 12
                     +=      present  on the left hand side after   a += b
                                                                                          a += 5            a = 15
                             performing addition
                             Returns  the  result to the  operand
                                                                                           a -= b            a = 8
                     -=      present  on the left hand side after   a -= b
                                                                                           a -= 5            a = 5
                             performing subtraction
                             Returns  the  result to the  operand
                                                                                           a *= b           a = 20
                     *=      present  on the left hand side after        a *= b
                                                                                           a *= 5           a = 50
                             performing multiplication
                             Returns  the  result to the  operand
                                                                                           a /= b            a = 5
                     /=      present  on the left hand side after        a /= b
                                                                                           a /= 5            a = 2
                             performing division
                             Returns the remainder to the operator
                                                                                          a %= b             a = 0
                     %=      present  on the left hand side after  a %= b
                                                                                          a %= 6             a = 4
                             performing division



                                                                                              Program Coding     61
   58   59   60   61   62   63   64   65   66   67   68