Understanding type promotion in C++ boolean arithmetic
This is a straightforward C++ language knowledge question that tests whether you understand how the compiler handles arithmetic operations on boolean operands. It is foundational for writing correct code and debugging unexpected type conversions.
When you perform arithmetic operations (including addition) on boolean values in C++, the language applies automatic type promotion rules. Rather than keeping the result as a boolean, the compiler follows a well-defined set of conversions that determine what type the expression actually evaluates to. This matters because it affects how the result behaves downstream—whether it can be assigned to different types, how it interacts with subsequent operations, and what values it can represent.
- Integral type promotion rules in C++
- Boolean-to-integer conversion semantics
- Operator overloading and built-in operator behaviour