Type Conversions in C Language – when an operator has operands of different types, they are converted to a common type according to type conversion rules.
This is called implicit (automatic) type conversion.
Automatic conversions are those that convert a ‘narrower’ operand to a ‘wider’ one (no loss of information).
Example, Conversion of int to float in f+i
Expressions that might lose some information, like assigning a floating point type to an integer, may draw a warning but not illegal.
Implicit Type Conversion Rules
- All chars and short ints are converted to ints. All floats are converted to doubles.
- In case of binary operators, if one of the two operands is a long double, the other operand is converted to long double, else if one operand is double, the other is converted to double, else if one operand is long, the other is converted to long, else if one operand is unsigned, the other is converted to unsigned.
It is possible to force an expression to be of specific type is called explicit type conversion or type casting.