--

설명

변수 값을 1 감소.

문법

x--; // x 를 1 감소시키고 옛 x 값 반환 --x; // x 를 1 감소시키고 새 x 값 반환

매개변수

  • x: 변수. 허용되는 자료형: integer, long (unsigned 가능)

반환값

  • 변수의 원래 또는 새로 감소된 값.

예제 코드

예제 코드 1

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

시리얼 모니터에 결과:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
x = 1 y = 1
Ln 11, Col 1
Arduino Uno on COM15
2

예제 코드 2

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

시리얼 모니터에 결과:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
x = 1 y = 2
Ln 11, Col 1
Arduino Uno on COM15
2

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