Most C operators perform type conversions to bring the operands of an expression to a common type or to extend short values to the integer size used in machine operations. The conversions performed by C operators depend on the specific operator and the type of the operand or operands. However, many operators perform similar conversions on operands of integral and floating types. These conversions are known as “arithmetic conversions.” Conversion of an operand value to a compatible type causes no change to its value.
The arithmetic conversions summarized below are called “usual arithmetic conversions.” These steps are applied only for binary operators that expect arithmetic type and only if the two operands do not have the same type. The purpose is to yield a common type which is also the type of the result. To determine which conversions actually take place, the compiler applies the following algorithm to binary operations in the expression. The steps below are not a precedence order.
The following code illustrates these conversion rules:
float fVal;
double dVal;
int iVal;
unsigned long ulVal;
dVal = iVal * ulVal; /* iVal converted to unsigned long
* Uses step 4.
* Result of multiplication converted to double
*/
dVal = ulVal + fVal; /* ulVal converted to float
* Uses step 3.
* Result of addition converted to double
*/