Skip to main content
The += operator is a compound assignment operator in C that performs addition and assignment in a single operation. It adds the value of the right operand to the left operand and stores the resulting value in the left operand.
Semantically, the expression E1 += E2 is equivalent to E1 = E1 + (E2), with one critical distinction: the left operand (E1) is evaluated exactly once. The parentheses around E2 are mandated by the C standard to preserve operator precedence. Without them, an expression with lower precedence than addition would evaluate incorrectly. For example, x += 1 << 2 evaluates to x = x + (1 << 2) (adding 4), whereas the unparenthesized expansion x = x + 1 << 2 would evaluate as x = (x + 1) << 2.

Operand Constraints and Type Behavior

The behavior of the += operator depends strictly on the data types of its operands: 1. Arithmetic Types If both operands are of arithmetic types (integer or floating-point), the compiler performs the usual arithmetic conversions to determine a common type for the addition. After the addition is computed, the result is implicitly cast back to the type of the lvalue before assignment.
2. Pointer Types If the left operand is a pointer, it must point to a completely defined object type. The right operand must be of an integer type. The operation performs standard pointer arithmetic: the integer value is scaled by the size of the type the pointer points to (sizeof(*lvalue)), and the pointer’s memory address is advanced by that scaled amount.

Evaluation and Side Effects

Because the lvalue is evaluated only once, the += operator guarantees safe execution for expressions that mutate state or invoke functions during address resolution.

Return Value, Type, and Associativity

  • Value: The result of a += expression is the new value of the left operand after the assignment has taken place.
  • Type: The type of the evaluated assignment expression is the type the left operand would have after lvalue conversion. Lvalue conversion strips type qualifiers. Therefore, if the left operand is a volatile int, the type of the evaluated expression is int, not volatile int.
  • Associativity: Like all assignment operators in C, += has right-to-left associativity. This allows for chained assignments, where the right-most expression is evaluated and assigned first.
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More