C++ Type Conversion/Type Casting

Typecasting is converting one data type into another one. It is also called as data conversion or type conversion. It is one of the important concepts introduced in ‘C++’ programming. The compiler will automatically change one type of data into another.

Type conversion in C can be classified into the following two types:

  • Implicit Type Conversion.
  • Explicit Type Conversion

Implicit Type Conversion

Implicit type casting means the conversion of data types without losing its original meaning. This type of typecasting is essential when you want to change data types without changing the significance of the values stored inside the variable.

Explicit type Conversion

These type of conversion performed by the programmer by posing the data type of the expression of a specific type is known as explicit type conversion. The explicit type conversion is also known as type casting.

data_type any c data type and expression may be constant, variable or expression.

The following rules have to be followed while converting the expression from one type to another to avoid the loss of information:

  • All integer types to be converted to float.
  • All float types to be converted to double.
  • All character types to be converted to an integer.