-- (decrement)

Description

Decrements the value of a variable by 1.

Syntax

  • x--; // decrement x by one and returns the old value of x
  • --x; // decrement x by one and returns the new value of x

Parameters

x
: variable. Allowed data types:
int
,
long
(possibly unsigned).

Returns

The original or newly decremented value of the variable.

Example Code

1x = 2;
2 y = --x; // x now contains 1, y contains 1
3 y = x--; // x contains 0, but y still contains 1

See also

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.