Type Conversion in C
Type Conversion in C
#include<stdio.h>
intmain()
// value of 'a' is 97
x = x + y;
floatz = x + 1.0;
return0;
}
Output:
1. x = 107, z = 108.000000
2. Explicit Type Conversion–
This process is also called type casting and it is user defined. Here the
user can type cast the result to make it of a particular data type.
The syntax in C:
(type) expression
Type indicated the data type to which the final result is converted.
#include<stdio.h>
intmain()
{
doublex = 1.2;
intsum = (int)x + 1;
return0;
Output:
sum = 2
Advantages of Type Conversion
This is done to take advantage of certain features of type
hierarchies or type representations.
It helps us to compute expressions containing variables of
different data types.