Skip to main content
The + operator in C++ is a built-in polymorphic token that functions as a unary arithmetic promotion operator, a binary arithmetic addition operator, and an offset operator for pointer arithmetic. It evaluates to a prvalue (pure rvalue) and is fully overloadable for user-defined types.

Unary Plus

The unary + operator returns the value of its operand. For narrow integer and unscoped enumeration types, it performs integral promotion. For floating-point types and pointers, it yields the exact same type without promotion.
  • Type Promotion: If the operand is a narrower integer type (e.g., char, short, bool) or an unscoped enumeration, it is promoted to int (or unsigned int). Floating-point types (e.g., float, double) and pointer types are not promoted to int.
  • Pointer Decay: When applied to an lvalue of an array or function type, the unary + forces an immediate decay to a prvalue pointer type.
  • Precedence: Level 3 (evaluated right-to-left).

Binary Addition

The binary + operator computes the sum of two arithmetic or unscoped enumeration operands. Scoped enumerations (enum class) are not supported by the built-in binary + operator.
  • Usual Arithmetic Conversions: Before the addition occurs, C++ applies the usual arithmetic conversions to bring both operands to a common type. For example, adding an int and a double results in the int being implicitly converted to a double, yielding a double prvalue.
  • Associativity: Left-to-right.
  • Precedence: Level 6.

Pointer Arithmetic

When one operand is a pointer to a completely-defined object type and the other is of an integral type, the + operator performs pointer arithmetic.
  • Scaling: The integral value is implicitly multiplied by the sizeof the type the pointer points to.
  • Result: It yields a new pointer of the same type, offset by the scaled integer.
  • Commutativity: The operation is commutative; the integer can appear on either the left or the right side of the operator.

Operator Overloading

For user-defined types (class, struct, enum), the + operator can be overloaded to define custom addition semantics. It can be implemented as either a member function or a non-member function. Non-Member Function (Preferred) Implementing operator+ as a non-member (often a friend) is the standard practice because it allows symmetric implicit conversions for both the left-hand side (LHS) and right-hand side (RHS) operands.
Member Function If implemented as a member function, the LHS is implicitly the this pointer. This prevents implicit conversions on the LHS operand.
  • Return Type: Overloads should return a new object by value (a prvalue), not by reference, to prevent dangling references and to adhere to the standard value-category semantics of the built-in + operator.
Tired of Poor C++ Skills? Fix That With Deep Grasping!Learn More