++ (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
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.

※ OUR MESSAGES