Page 65 - TP_iPlus_V2.1_Class8
P. 65

Example
                    Operator                  Description                  Syntax                          Output
                                                                                      (int a = 11, b = 4)
                       !=        This operator is  used to check the  (a != b)        a != b              true
                  Not Equal to inequality between two values.                         a != 11             false

                        >        This operator checks if the first value  (a > b)     (a > b)             true
                  Greater than is greater than the second value.                      (11 > 13)           false
                        <        This operator is used to check if the  (a < b)       (a < b)             false

                   Less than     first value is less than the second value.           (15 < 20)           true
                       >=        This operator is used to check if the  (a >= b)      (a >= b)            true
                  greater than  first value is greater than or equal to               (22 >= 22)          true
                    or equal     the second value.                                    (21 >= 23)          false

                       <=        This operator is used to check if the  (a <= b)      (a <= b)            false
                  less than or  first value is less than or equal to the              (30 <= 31)          true
                    equal to     second value.
                                                                                      (27 <= 27)          true

                 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’ value if all the  (a>b) && (b>c) (11 > 4) && (4 > 15)            false
                              given conditions are true.                       (11 > 4) && (15 > 4)       true
                 || (OR)      Returns  ‘true’  value if any  (a>b) || (b>c)    (11 > 4) || (4 > 15)       true
                              one of the given conditions                      (11 > 4) || (15 > 4)       true

                              is true.                                         (4 > 11) || (4 > 15)       false
                 NOT (!)      Returns  ‘true’  value  if the  ! (a > b)        !(11 > 4)                  false
                              condition returns false and                      !(4 > 11)                  true
                              vice-versa.
                 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 as result.     a ++        b = a++         a=12 b=11
                  increment
                      --       Returns the decremented value as result.      a --        b = a--        a=10 b=11
                  decrement






                                                                                                                  63
                                                                                               Program Coding
   60   61   62   63   64   65   66   67   68   69   70