typecasting involves converting a value from one data type to another. This can be useful in situations where you need to perform operations or comparisons involving different data types. In most programming languages, typecasting can be achieved using predefined functions or syntax.
(type name)operands;
S.No | function | Discription |
---|---|---|
1 | (int) | It convert any datatype into integer. |
2 | (float) | It convert any datatype into Float. |
3 | (char) | It convert any datatype into charecter. |
4 | (str) | It convert any datatype into strings |
#include<stdio.h> int main() { int a=10, b; char z='4', x; float k=4.000, j; b = ((int)z) / 2; x = char(int(k) + a); j = float(float(a) / k); printf("%d %c %f", b, x, j); return 0; }
Here b contains integer value x contains integer char value and j conatins float value.