C – Type Casting functions
- Typecasting concept in C language is used to modify a variable from one date type to another data type. New data type should be mentioned before the variable name or value in brackets which to be typecast.
C type casting example program:
- In the below C program, 7/5 alone will produce integer value as 1.
- So, type cast is done before division to retain float value (1.4).
int main ()
x = (float) 7/5;
- It is best practice to convert lower data type to higher data type to avoid data loss.
- Data will be truncated when higher data type is converted to lower. For example, if float is converted to int, data which is present after decimal point will be lost.
Inbuilt typecast functions in C:
- There are many inbuilt typecasting functions available in C language which performs data type conversion from one type to another.
- Click on each function name below for description and example programs.
||Converts string to float
||Converts string to int
||Converts string to long
||Converts int to string
||Converts long to string
Share this C programming language with your friends