Page 32 - Modular_V1.1_Flipbook
P. 32

Explicit Type Casting

                  Explicit type casting means to convert one data type into another using typecast operator. A
                  typecast operator consists of a data type in parentheses. For example:

                  int i = 10;
                  float f;
                  f = (float) i;

                  In the preceding code, the int type value is converted into float type. We use explicit typecasting
                  when C++ does not do a needed conversion automatically.
                      Recap


                          An operator is a symbol used to perform mathematical and logical calculations.
                         Arithmetic operators are general mathematical operators used to perform arithmetic operations.
                         Relational operators are used to compare the value of the two operands and return True or
                         False accordingly.
                         Logical operators are used to combine more than one relational expression.
                         Assignment operators are used to assign the value of the right-hand operand to the left-hand
                         operand.
                         C++ provides increment (++) and decrement (– –) operators which are used to increase or
                         decrease the value of a variable by 1.
                         A ternary operator requires three operands to work.
                         An expression is  a combination of variables or values with operators  which are  arranged
                         according to the rules of the language.
                         Type casting means to convert one data type into another data type.


                                                         Exercise




                  A.   Tick (3) the correct option.
                       1.  Which of the following is not a category of operators in C++?
                           a.  Arithmetic                                   c.  Relational
                           b.  Logical                                     d.  Scientific

                       2.  Which of the following operators is used to increase the value of a variable by 1?
                           a.  Assignment                                   c.  Increment
                           b.  Ternary                                     d.  Decrement

                       3.  Which type of operators need two operands to work?
                           a.  Unary                                        c.  Ternary
                           b.  Binary                                      d.  None of these

                       4.   Which of the following is a combination of variables or values with operators?
                           a.  Relation                                     c.  Condition

                           b.  Operator                                    d.  Expression



                  30      Touchpad MODULAR (Version 1.1)-X
   27   28   29   30   31   32   33   34   35   36   37