Type Conversion in C
Type Conversion simply means that conversion from one type (data type) to another. There are two types of type conversion in C language.
1. Automatic or Implicit Conversion : When operands of different data types are used in an arithmetic expression, one of the operand data types will be converted to the type another operand. This conversation is taking place automatically during program execution that is called Automatic Type Conversation or Implicit Conversion.
The order of this conversion is as follows :
char --> int --> long int --> float --> double (low ranking) (high ranking) Example : int m=25 float x=5.5, y; y=m*x; // The result obtained by Automatic Type Conversation which is converted int to float data types.
2. Type Casting or Explicit Conversion : Type Casting or Explicit Conversion is used to overcome Automatic Conversation. The variable declared in specific data type can be converted into another data type.
(type) expression or (type) (expression) Example : int m=5; float y; y=(float)m/2; // The result obtained by Explicit Conversion which is converted int into float data types and get result y=2.5;