Professional Documents
Culture Documents
14 TYPE CASTING
Te conversion of one data type to another is known as type casting or type conversion.
(1) Implicit: In this situation, the compiler casts the values of distinct data types in an
int → unsigned int → long → unsigned long → long long → unsigned long long → foat
Example:
Here, because foat data type is higher in the hierarchy between foat and int, the arithme c
expression total/count gives a foat value.
(2) Explicit: In this situation, the programmer uses the cast operator to explicitly
(type_name) expression
Example:
First, the total is transformed from an int to a foat, and then division is performed. Because
total has been converted to foat and count has been changed to int, the result is a decimal
value because foat is higher in the hierarchy than int data type.