Increment (++) and Decrement ( -- ) Operators
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Increment (++) and Decrement (--) Operators

Increments or decrements the value of a variable by one.

Prefix Syntax


Postfix Syntax



Any numeric variable.


The increment and decrement operators are used as a shortcut to modify the value stored in a variable and access that value. Either operator may be used in a prefix or postfix syntax.

If Equivalent Action Return value
++variable variable += 1 value of variable after incrementing
variable++ variable += 1 value of variable before incrementing
--variable variable -= 1 value of variable after decrementing
variable-- variable -= 1 value of variable before decrementing


The following example illustrates the difference between prefix and postfix syntax for the ++ operator.

// Example of prefix increment operator
var j1 : int = 2;
var k1 : int;
k1 = ++j1;          // k1 is 3, the value of j1 after incrementing

// Example of postfix increment operator
var j2 : int = 2;
var k2 : int;
k2 = j2++;          // k2 is 2, the value of j2 before incrementing


Version 1

See Also

Operator Precedence | Operator Summary

© 2015 Microsoft