Typecasting in c

 

Typecasting in C -It is possible to force an expression to be a specific type by using an operator called a cast. These force conversions are called explicit type conversions.

The syntax of Typecasting in C

(type) expression

where type is the standard C data type. For example, if you want to make sure that the expression a/5 would evaluate to type float you would write it as

( float ) a/5

cast is an unary operator and has the same precedence as any other unary operator.

The use of cast operator is explained in the following example:

main()
{
int num;
printf(“%f %f %f\n”, (float)num/2, (float)num/3, float)num/3);
}

 

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: