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 operator that subtracts one from the value of its operand. It requires a modifiable lvalue of an arithmetic type (explicitly excluding bool, which the C++ standard forbids), a pointer type, or a class type that explicitly overloads the operator.
The operator exists in two distinct forms, which differ in their evaluation order and resulting value categories:
Prefix Decrement (--x)
The prefix form decrements the operand’s value and evaluates to the modified object. For built-in types, the expression does not have a reference type; rather, it evaluates as an lvalue of the operand’s underlying type.
- Type:
T(whereTis the type of the operand). - Value Category: Lvalue.
- Evaluation: The decrement operation is sequenced before the value computation of the expression.
Postfix Decrement (x--)
The postfix form evaluates to the original value of the operand, then decrements the operand’s underlying value.
- Type:
T(whereTis the type of the operand). - Value Category: Prvalue.
- Evaluation: The value computation of the expression is sequenced before the decrement operation.
Pointer Arithmetic Semantics
When applied to a pointer, the-- operator does not simply subtract the integer 1 from the memory address. Instead, it decrements the address by the byte size of the pointed-to type (sizeof(T)). The operand must be a pointer to a completely defined object type; it cannot be applied to void* or function pointers. To avoid Undefined Behavior, pointer arithmetic is only well-defined when the pointer points to an element of an array object (or one past the end of it).
Operator Overloading
For user-defined types, both forms of the-- operator can be overloaded. The C++ compiler differentiates between the prefix and postfix overloads via a dummy int parameter injected into the postfix signature during overload resolution.
The C++ language does not enforce specific return types for overloaded operators; they can legally return void, int, or any other type. However, returning T& for prefix and T for postfix is a strong convention required to satisfy standard library concepts (such as iterators) and to mimic built-in semantics.
Master C++ with Deep Grasping Methodology!Learn More





