When Implicit Conversions Occur

The compiler automatically converts operands in the following circumstances:

• In most expressions, values of integral types smaller than int are first promoted to an appropriate larger integral type.

• In conditions, nonbool expressions are converted to bool.

• In initializations, the initializer is converted to the type of the variable; in assignments, the right-hand operand is converted to the type of the left-hand.

• In arithmetic and relational expressions with operands of mixed types, the types are converted to a common type.

• As we’ll see in Chapter 6, conversions also happen during function calls.

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.