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 type will be converted to the type other 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 obatined 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 obatined by Explicit Conversion which is converted int into float data types and get result y=2.5;