Changing the type of the variable is known as type casting or type conversion.
There are two type of type conversion in C
Implicit Type conversion
Explicit Type conversion
Implicit:
program-
#include< stdio.h>
int main()
{
int x=20;
char y="a";
//convert character to integer
// Here y is 97
x = x + y;
// x is implicitly converted to float
float z = x + 1.0;
printf("x is %d\nz is %f", x, z);
return 0;
}
x is 107
z is 108.000000
#include< stdio.h>
int main()
{
double x=3.2;
// Explicit conversion from double to int
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
sum=4