> ## 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 Remainder Assignment

The `%=` (modulo assignment) operator is a compound assignment operator that computes the remainder of the division of its left operand by its right operand, and subsequently assigns that resulting value back to the left operand.

## Syntax and Equivalence

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

According to the C standard (C11 6.5.16.2), this expression is semantically equivalent to:

```c theme={"dark"}
lvalue = lvalue % (rvalue);
```

The parentheses around the `rvalue` are strictly required in this equivalence due to operator precedence. Without them, an expression like `d %= e + 1` would incorrectly expand to `d = d % e + 1` (which evaluates as `(d % e) + 1`), rather than the correct `d = d % (e + 1)`.

Additionally, in the compound assignment (`%=`), the `lvalue` is evaluated exactly once. This is a critical distinction from the expanded form when the left operand contains side effects (e.g., `array[i++] %= 2;`).

## Technical Constraints

* **Operand Types:** Both the left and right operands **must** be of integral types (e.g., `char`, `short`, `int`, `long`, `long long`, or their `unsigned` variants).
* **Floating-Point Restriction:** Applying `%=` to floating-point types (`float`, `double`) violates C language constraints and will result in a compilation error.
* **Modifiable Lvalue:** The left operand must be a modifiable lvalue. It cannot be a `const`-qualified variable or a literal.
* **Associativity:** Like all assignment operators in C, `%=` has right-to-left associativity.

## Evaluation Rules and Edge Cases

* **Sign of the Remainder:** Under the C99 standard and later, the truncation of integer division is always toward zero. Consequently, the sign of the result of a modulo operation always matches the sign of the dividend (the left operand). The sign of the divisor (the right operand) does not affect the sign of the result.
* **Undefined Behavior:**
  * **Division by Zero:** If the right operand evaluates to `0`, the operation triggers undefined behavior, typically manifesting as a hardware exception.
  * **Unrepresentable Quotient:** If the quotient of the underlying division is not representable, the behavior of both the division (`/`) and modulo (`%`) operators is undefined (C11 6.5.5p6). For two's complement signed integers, this occurs if the minimum representable value of a type is moduloed by `-1` (e.g., `INT_MIN %= -1`). Because the mathematical quotient (`INT_MAX + 1`) cannot be represented in the signed type, it triggers undefined behavior.

## Mechanical Examples

```c theme={"dark"}
int a = 10;
a %= 3;     // a evaluates to 1 (10 / 3 = 3, remainder 1)

int b = -10;
b %= 3;     // b evaluates to -1 (sign matches the left operand)

int c = 10;
c %= -3;    // c evaluates to 1 (sign matches the left operand)

int d = 5;
int e = 2;
d %= e + 1; // Evaluated as d = d % (e + 1). d becomes 2 (5 % 3)

#include <limits.h>
int f = INT_MIN;
// f %= -1; // WARNING: Undefined behavior (unrepresentable quotient)
// f %= 0;  // WARNING: Undefined behavior (division by zero)
```

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