Difference between Type Casting and Type Conversion

Difference between Type Casting and Type Conversion

1. Type Casting:
In typing casting, a data type is converted into another data type by the programmer using the casting operator during the program design. In typing casting, the destination data type may be smaller than the source data type when converting the data type to another data type, that’s why it is also called narrowing conversion.

2. Type conversion :
In type conversion, a data type is automatically converted into another data type by a compiler at the compiler time. In type conversion, the destination data type cannot be smaller than the source data type, that’s why it is also called widening conversion. One more important thing is that it can only be applied to compatible data types.

 

Let’s see the difference between Type casting and Type conversion which are given below:

S.NO TYPE CASTING TYPE CONVERSION
1. In type casting, a data type is converted into another data type by a programmer using casting operator. Whereas in type conversion, a data type is converted into another data type by a compiler.
2. Type casting can be applied to compatible data types as well as incompatible data types. Whereas type conversion can only be applied to compatible datatypes.
3. In type casting, casting operator is needed in order to cast the a data type to another data type. Whereas in type conversion, there is no need for a casting operator.
4. In typing casting, the destination data type may be smaller than the source data type, when converting the data type to another data type. Whereas in type conversion, the destination data type can’t be smaller than source data type.
5. Type casting takes place during the program design by programmer. Whereas type conversion is done at the compile time.
6. Type casting is also called narrowing conversion because in this, the destination data type may be smaller than the source data type. Whereas type conversion is also called widening conversion because in this, the destination data type can not be smaller than the source data type.

For any query or issue, feel free to discuss on http://discuss.eduguru.in