Type casting in C

Type casting

In c, it permits the mixing of constants and variables of different data types in an expression. Typecasting is defined as the conversion of the datatype of one variable to another data type.
There are two ways of typecasting in c –

                  1. Implicit type casting 

                  2. Explicit type casting

1. Implicit type casting:

C automatically converts any intermediate values to the proper type so that the expression can be evaluated without losing any significance. This automatic conversion is known as implicit type conversion. All the data types of the variables are upgraded to the data type of the variable with the largest data type.

bool -> char -> short int -> int -> unsigned int -> long -> unsigned -> long long -> float -> double -> long double


Explanation :

Here the value of C will be 12.3, where the value of ‘a’ will be implicitly converted to float.

2. Explicit type casting :

This process is also called type casting and it is user-defined. Here the user can typecast the result to make it of a particular data type.

Syntax:  (datatype)expression