> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C Addition Assignment

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.

```c theme={"dark"}
lvalue += rvalue;
```

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.

```c theme={"dark"}
int a = 5;
double b = 3.14;
a += b; // 'a' evaluates to 8. 'b' is added to 'a', and the 8.14 result is truncated to int.
```

**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.

```c theme={"dark"}
int arr[5];
int *ptr = arr;
ptr += 3; // Advances the pointer by (3 * sizeof(int)) bytes.
```

## 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.

```c theme={"dark"}
// The function get_target_pointer() is executed exactly once.
// If expanded to *get_target_pointer() = *get_target_pointer() + (5), 
// the function would be erroneously executed twice.
*get_target_pointer() += 5; 
```

## 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.

```c theme={"dark"}
int x = 1, y = 2, z = 3;
x += y += z; 
// Evaluates as: x += (y += z)
// y becomes 5, then x becomes 6.
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
