C++ automatically performs certain conversions. These are categorised and explained in this section.
A character, a short integer, an enumerated type identifier or a bit field are automatically promoted to integer type as required. If a signed integer can be used to represent the value being promoted, the original value is converted to integer. If an unsigned integer is required to represent the original object, the promotion is to unsigned integer.
When an integer is converted from signed to unsigned type, if no truncation occurs, the resultant value is the unsigned integer equivalent of the original signed value. If truncation occurs (going from int to unsigned short int say), the resultant value is the original value modulo 2<<n, where n is the number of bits used to represent the unsigned quantity. See the section titled numeric representation, (subsection: Two's Complement Arithmetic) for a pictorial explanation of this topic.
When an integer is converted from unsigned to signed type, if the target of the conversion is capable of holding the bit pattern, no change to the pattern takes place - the result is merely reinterpreted as a signed value. If the target is unable to hold the new value, the result is implementation dependent.
Single precision floating point (float) values may be converted to double precision floating point values (double) without changing the numeric value during the conversion. Conversion from a lower to a higher precision floating point representation without change to the numeric value is always possible. When converting from a more precise to less precise representation (such as from double to float), if the number is exactly representable then no change takes place. If not, the next higher or lower representation of the number is used (in the lower precision system). If the result of the conversion is out of range in the lower precision system, the effect is undefined.
The conversion of a floating point quantity to an integral value causes the decimal portion of the floating point number to be discarded. The direction of the truncation of a negative number is machine dependent.
The precision of the conversion of integers to floating point also varies according to the machine architecture. Integers are exactly representable on modern Intel platforms.
Conversions that are made during the course of arithmetic expression evaluation are performed in accordance with the rules stated below. The rules are applied in the order of precedence of their listing and operands refers to the operands of a binary arithmetic operator.
The following standard conversions apply to pointers.
Reference conversion may take place when references are:
A reference to an instance of a class T may be converted to a reference to an instance of an accessible, unambiguous, base class of T. The resultant reference is to the sub-object contained in the derived class.
The following standard conversions apply to pointers to members.