What is mean by Type Casting in c
Typecasting
involves converting an expression of a given type into another type. In C, you
can perform typecasting by placing the data type name in parentheses and
placing this in front of the value. For example:
int main()
{
int x;
x = (int)8 / 6;
return 0;
}
In the above example, the usual result of 8/6 should be 1.3333 but since we have typecasted it, the x value would be "1". The later part is simply dropped.
int main()
{
int x;
x = (int)8 / 6;
return 0;
}
In the above example, the usual result of 8/6 should be 1.3333 but since we have typecasted it, the x value would be "1". The later part is simply dropped.
Typecasting is very essential in programming to avoid any
unnecessary errors or warnings. Sometimes C compilers need you to define as to
what type of typecasting is needed whereas on the other it implicitly converts.
The usual notification is "()". Typecasting
is like you want to make a variable of one type, such as an int, to act like
another type, such as char, for single statement. Although typecast has so many
benefits but still it is considered as a headache because it simply truncates
your data at important steps