1.

What is implicit type conversion. Explain with a suitable example.

Answer»

Implicit type conversion is an automatic type conversion done by the compiler whenever data from DIFFERENT types is intermixed. Implicit conversions of scalar built-in types defined in Table 4.1 (except void, double,1 and half 2) are SUPPORTED. When an implicit conversion is done, it is not just a reinterpretation of the expression's value but a conversion of that value to an equivalent value in the new type.

Consider the following example:

float f = 3; // implicit conversion to float value 3.0

INT i = 5.23f; // implicit conversion to integer value 5

In this example, the value 3 is converted to a float value 3.0f and then assigned to f. The value 5.23f is converted to an int value 5 and then assigned to i. In the second example, the FRACTIONAL part of the float value is dropped because integers cannot SUPPORT fractional values; this is an example of an unsafe type conversion.




Discussion

No Comment Found