1.

(a)Differentiate between implicit and explicit types of conversion withsuitable examples.

Answer»

Conversion of one data type to another data type. and it can be done in two ways.1. Implicit Type Casting2. Explicit Type Casting

Implicit type casting is performed by the compiler on its own when it encounters a mixed data type expression in the program. it is also known as automatic conversion as it is done by compiler without programmer’s assistance. implicit casting doesn’t require a casting operator.

Example :-int a=42;float b=a;Here b will contain typecast value of a, because while assigning value to b compiler typecasts the value of a into float then assigns it to b.

Explicit type casting is performed by the programmer. In this type casting programmer tells compiler to type cast one data type to another data type using type casting operator. but there is some risk of information loss is there, so one needs to be careful while doing it.

Example :-float a=42.12;int b=(int)a;

Here we explicitly converted float value of a to int while assigning it to int b. (int) is the type casting operator with the type in which you wants to convert.



Discussion

No Comment Found