Type Casting

 Type Casting


Type cast is an instruction to the compiler to convert one type into another.

For example, if you want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'.

Here, target-type specifies the desired type to convert the specified expression to.

You can convert the values from one type to another explicitly using the cast operator as follows:(type_name) expression

When a cast involves a narrowing conversion, information might be lost.For example, when casting a long into a short ,information will be lost if the long’s value is greater than the range of a short because its high-order bits are removed. When a floating-point value is cast to an integertype, the fractional component will also be lost due to truncation.


#include <stdio.h>

int main()

{

        int sum = 17, count = 5;

        double mean;

        mean = sum / count;

        printf("Value of mean : %f\n", mean );

        return 0;

}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.