++ (遞增運算子) / — (遞減運算子)

描述

遞增或遞減一個變數

語法


x++; // x 增加 1 並回傳舊的數值
++x; // x 增加 1 並回傳新的數值

x-- ; // x 減少 1 並回傳舊的數值
--x ; // x 減少 1 並回傳新的數值

參數

x: 一個整數或者長整數型態(可以用unsigned型態)

回傳值

原始數值或是經過遞增(遞減)的數值。

範例

x = 2;
y = ++x;      // x 現在是3,y 也是3
y = x--;      // x 變回2,y 仍然是3

See also

+= (compound addition)
-= (compound subtraction)


語法參考主頁面

本頁由熱血青年 LBU 譯自英文版。

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.