Page 48 - CA_Blue( J )_Class10
P. 48

3.8.2 Explicit Type Conversion
              In explicit type conversion, we can assign a value of larger data type to a smaller data type. It is a process of narrowing.
              This is useful for incompatible data types where automatic conversion cannot be done. It requires user's intervention.
              Here, the target type specifies the desired type to convert the specified value to.




              Syntax for explicit type conversion is:

                 <data type> variable = (data type) variable_to_be_converted;
              For example:

                 float a = 10;
                 int b = (int)a;
              Let us take an example:


















              You will get the following output:
















              The boolean data type is not compatible with any other primitive data type. So, it cannot be converted to any other
              type or vice versa neither by implicit nor explicit data type conversion.















              It returns an error "incompatible types: char cannot be converted to boolean".








                4646  Touchpad Computer Applications-X
   43   44   45   46   47   48   49   50   51   52   53