Home

postdecrement

The postdecrement operator, commonly written as x--, is a postfix unary operator found in many programming languages. It decreases the value of its operand by 1 while returning the operand's original value.

In languages such as C, C++, Java, and JavaScript, the operator is applied as a side effect

Examples: int i = 5; int a = i--; // a becomes 5, i becomes 4. In an array access,

Precedence and evaluation: Postfix decrement generally binds tightly in expressions, higher than most binary operators, and

Usage notes and pitfalls: In C/C++, using i-- in the same expression as other reads or writes

Other languages: not all languages include a postdecrement operator. Python, for example, does not have i--. Some

---

after
the
value
is
produced.
The
result
of
the
expression
is
the
value
before
the
decrement;
the
operand
is
reduced
by
1
for
subsequent
use.
arr[i--]
uses
the
current
i
as
the
index,
then
i
is
decremented.
The
postfix
form
contrasts
with
the
prefix
decrement,
--i,
which
decrements
first
and
returns
the
new
value.
is
evaluated
after
the
operand's
value
is
obtained
but
before
control
proceeds
to
the
next
sequence
point
in
languages
that
distinguish
sequencing.
of
i
can
cause
undefined
behavior
if
not
properly
sequenced.
In
scripting
languages
like
JavaScript,
the
operator
is
well
defined
for
common
usages
but
can
produce
surprising
results
in
complex
expressions.
languages
expose
similar
behavior
with
function
calls
or
methods
rather
than
operators.