TYPE CASTING

It is used to convert on data at a time. It is required to used different type of constants and variables in expression then we have convert that expression into another data type, but certain rules are used during conversion of data type the computer consider one operand at a time involving two operands. We can have two types of type casting.

1. Implicit

2. Explicit

Implicit

When we are converting any data type which contains shorter values then along data type that conversion is called implicit or in simple language we can say when user do not need to convert any data type into another data type and it is automatically done through computer system that is called implicit type conversion. The conversion is not transparent to the user or the programmer and is done by the compiler. This converts narrow type to wider type so that use can avoid the information to the system.

#include

void main ()

{

float c,f;

clrscr ();

printf ("Enter the value of celcius: ");

scanf ("%f",&c);

f=9.0/5.0*c+32;

printf ("\Fehranite is %.2f",f);

getch ();

}

Explicit

Explicit type casting is done by the programmer manually. When the programmer wants a result of an expression to be in particular type, then we use explicit type casting. This type casting is done by casting operators ‘( )’ and data type.

#include

void main ()

{

float c,f;

clrscr ();

printf ("Enter the value of celcius: ");

scanf ("%f",&c);

f=(float) 9/5*c+32;

printf ("\Fehranite is %.2f",f);

getch ();

}