Page 64 - iprime_V2.2_class8
P. 64

Logical Operators

                  Logical operators are used to combine multiple conditions and evaluate them. They return a
                  Boolean value ‘True’ or ‘False’ as result.

                   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







                  62     iPRIME (Ver. 2.2)–VIII
   59   60   61   62   63   64   65   66   67   68   69