TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-- (decrement) operator is a unary arithmetic operator that decreases the value of its operand by one. The operand must be a modifiable lvalue of a scalar type (an integer, a floating-point number, or a pointer to a complete object type).
The operator exists in two distinct forms, which differ strictly in how the expression’s value computation is sequenced relative to the side effect of modifying the stored value of the operand.
Prefix Decrement
In the prefix form, the operator precedes the operand.- Side Effect: The value of the
operandis decreased by 1. - Value Computation: The expression evaluates to the new, decremented value of the operand.
operand -= 1. It is strictly not equivalent to operand = operand - 1 because the -- operator evaluates its operand exactly once. This prevents multiple evaluations of expressions with side effects (e.g., in --a[i++], the index i is incremented only once, whereas a[i++] = a[i++] - 1 evaluates i++ twice, invoking Undefined Behavior).
Postfix Decrement
In the postfix form, the operator succeeds the operand.- Value Computation: The expression evaluates to the original value of the
operand(the value before the decrement occurs). - Side Effect: The value of the
operandis decreased by 1.
Value Category (Rvalue Result)
In C, the result of both the prefix and postfix decrement operators is an rvalue (a value, not an object). This is a critical distinction from C++ (where prefix decrement yields an lvalue). Because the result is an rvalue, it does not have an identifiable memory location, which strictly prohibits chaining decrement operators or taking the address of the result.Type-Specific Mechanics
The exact mechanical behavior of the decrement operation depends on the scalar type of the lvalue:- Arithmetic Types (Integer/Floating-Point): The operator subtracts exactly
1(or1.0) from the current value. - Pointer Types: When applied to a pointer of type
T*,Tmust be a complete object type. The operator does not strictly subtract 1 from the memory address; instead, it decrements the address by the size of the pointed-to type (sizeof(T)). Decrementing a pointer to an incomplete type (such asvoid*or a forward-declaredstruct) is a constraint violation in standard C because the size of the type is unknown.
Technical Constraints and Undefined Behavior
- Lvalue Requirement: The
--operator requires a modifiable lvalue. It cannot be applied to literals, constants, or the results of expressions that yield rvalues.
- Sequence Points: Modifying the same scalar object multiple times between two sequence points, or modifying an object and reading its value for a purpose other than determining the value to be stored, results in Undefined Behavior (UB).
Master C with Deep Grasping Methodology!Learn More





