Monday, January 18, 2016

Types of Type Casting in C: Upcasting and Downcasting

There are two type of casting available in C language, known as upcasting and downcasting. Upcast means converting lower (like int) to higher (float, long int) data type. The reverse is called downcast. 
Upcast results in no information loss. But downcast results in information loss as lower data type have lesser bits and can hold the lesser amount of information/data. One data type considers higherif maximum value allowed to store in it is greater than the other data type. For example, float is lower compared to double because double can store more precisions

Second program in this chapter is example of upcasting(int value is converted to float) and the third program is example of down casting(float is converted to int)
C Type Casting with examples for Float to Int/Int to Char

No comments: