++ ⇝

increment operator

<programming>

A programming language unary operator that adds one to its operand. Similarly, a decrement operator subtracts one from its operand.

In the B programming language and its many descendents (e.g. C, Perl, Java), the increment operator is written "++" and decrement "--". They can be either prefix or postfix, both of which return a value as well as changing their operand. The prefix form, e.g. ++x, increments variable x before returning its value whereas postfix, x++, returns x's original value before it was incremented.

The expression ++x is equivalent to the assignment operator, x += 1. There is no simple corresponding equivalent for x++. These expressions, ++x, x++, x += 1 are almost equivalent to the long form x = x + 1 except that the latter involves two references to x. In the case of a simple variable, this makes no difference but the operand can be any lvalue (something that can be assigned to), including a complex pointer expression whose value changes each time it is evaluated.

If the operand is a pointer then incrementing it (in any of the above ways) causes it to point to the next element of its specified type.

The name of the programming language C++ is a humourous use of the postfix increment operator to imply that C++ is "one better than" C.

Last updated: 2019-07-14

Nearby terms:

Incremental Prototyping Technology for Embedded Realtime Systemsincrement operatorindent

Try this search on Wikipedia, Wiktionary, Google, OneLook.



Loading