++ (incremento)
Descripción
Incrementa una variable
Sintaxis
x++; // incrementa x en una unidad y devuelve el anterior valor de x
++x; // incrementa x en una unidad y devuelve el nuevo valor de x
Parámetros
- x: un int o long (posiblemente sin signo)
Retornos
- El original o nuevo valor incrementado de la variable.
Ejemplo
Ejemplo 1
void setup() {
Serial.begin(9600);
int x = 2;
int y = ++x; // x ahora contiene 3, y contiene 3
Serial.print("x = ");
Serial.println(x);
Serial.print("y = ");
Serial.println(y);
}
void loop() {
}
The result on Serial Monitor:
COM6
x = 3
y = 3
Autoscroll
Clear output
9600 baud
Newline
Ejemplo 2
void setup() {
Serial.begin(9600);
int x = 2;
int y = x++; // x contiene 3 de nuevo, y todavÃa contiene 2
Serial.print("x = ");
Serial.println(x);
Serial.print("y = ");
Serial.println(y);
}
void loop() {
}
The result on Serial Monitor:
COM6
x = 3
y = 2
Autoscroll
Clear output
9600 baud
Newline
Ver También
- Lenguaje: += (Suma compuesta)
- Lenguaje: |= OR bit a bit compuesto
- Lenguaje: /= (División compuesta)
- Lenguaje: *= (Multiplicación compuesta)
- Lenguaje: %= (Módulo compuesto)
- Lenguaje: -= (Resta compuesta)
- Lenguaje: -- (decremento)
※ 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.
Follow Us