Increment Decrement Operators

The final two general arithmetic operators are the increment and decrement operators. Both are unary operators, so only one operand is required, and they may be placed on either side of the operand. If the entire statement consists of just the operand and this operator, then whether the operator is prefixed or postfixed does not matter.

For example:
x++;
and
++x;
yield the same results.

Operator Operation Example Result
++ Increment x++
++x
Use x then increment x by 1
Increment x by 1, then use x
-- Decrement x--
--x
Use x then decrement x by 1
Decrement x by 1, then use x

Postfix Example

Prefix Example

However, if this operator is used as part of a larger expression, then the position of the operator becomes significant. When the operator is postfixed as in the example on the left, this means use the value of x first when evaluating the expression, then increment x afterward. When it is prefixed as in the example on the right, this means increment the value of x first, then use that new value in the evaluation of the expression.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.