++ (incrément)

Description

Incrémente une variable

Syntaxe

x++; // incrémente x de un, sans modifier x ++x; // incré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 incrémentée de la variable.

Exemple

Exemple 1

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

The result on Serial Monitor:

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

Exemple 2

void setup() { Serial.begin(9600); int x = 2; int y = x++; // x contient 3, 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 = 3 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.