-- (décrément)

Description

Décrémente une variable

Syntaxe

x--; // décrément x de un, sans modifier x --x; // décrémente x de un, et modifie x

Paramètres

  • x: une valeur entière de type int ou long, (pouvant être unsigned)

Valeurs Renvoyées

  • La valeur de x ou la nouvelle valeur décrémentée de la variable.

Exemple

Exemple 1

void setup() { Serial.begin(9600); int x = 2; int y = --x; // x contient 1 et y contient 1 Serial.print("x = "); Serial.println(x); Serial.print("y = "); Serial.println(y); } void loop() { }

The result on Serial Monitor:

COM6
Send
x = 1 y = 1
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Exemple 2

void setup() { Serial.begin(9600); int x = 2; int y = x--; // x contient 1, y contient 2 Serial.print("x = "); Serial.println(x); Serial.print("y = "); Serial.println(y); } void loop() { }

The result on Serial Monitor:

COM6
Send
x = 1 y = 2
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES

  • We are AVAILABLE for HIRE. See how to hire us to build your project
  • Any suggestion, correction, and translation? please email us at ArduinoGetStarted@gmail.com, We appreciate it
  • We mainly keep improving the references in English. See English version of this page for the latest update.