Skip to main content

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.

The -= (subtraction assignment) operator is a compound assignment operator in C that subtracts the value of the right operand from the left operand and stores the resulting value back into the left operand.
lvalue -= expression;
The expression E1 -= E2 is semantically equivalent to E1 = E1 - (E2), with the critical distinction that the left operand E1 is evaluated exactly once. This single evaluation guarantees safe execution when the left operand contains side effects, such as a function call or a post-increment operation (e.g., array[i++] -= 5). Operand Constraints
  • Left Operand (lvalue): Must be a modifiable lvalue. It can be of any arithmetic type (integer or floating-point) or a pointer to a completely defined object type.
  • Right Operand (expression): Must be an arithmetic type. If the left operand is a pointer, the right operand must be an integer type.
Type Conversion and Mechanics
  • Arithmetic Types: When both operands are arithmetic, the compiler applies the usual arithmetic conversions to determine a common type for the subtraction. After the subtraction is performed, the result is implicitly truncated or promoted back to the type of the left operand before the assignment occurs.
  • Pointer Types: When the left operand is a pointer, the operator performs pointer arithmetic. The integer right operand is scaled by the size of the type the pointer points to. The pointer’s memory address is decremented by expression * sizeof(*lvalue) bytes.
Return Value The result of the -= operation is the new value of the left operand after the assignment has occurred. The type of the result is the type of the left operand. In C, this resulting value is an rvalue, meaning the expression itself cannot be placed on the left side of a subsequent assignment operation.
Master C with Deep Grasping Methodology!Learn More