++

설명

변수 값을 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 3, y contains 3 Serial.print("x = "); Serial.println(x); Serial.print("y = "); Serial.println(y); } void loop() { }

시리얼 모니터에 결과:

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

예제 코드 2

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

시리얼 모니터에 결과:

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.