ArduinoのSketch(スケッチ)で使用できる複合演算子について解説します。
Arduinoで使用できる複合演算子は、次表の通りです。
| Compound Operators | Description |
|---|---|
| ++ | increment |
| -- | decrement |
| += | compound addition |
| -= | compound subtraction |
| *= | compound multiplication |
| /= | compound division |
| &= | compound bitwise and |
| |= | compound bitwise or |
使用方法は、C言語と同様です。
//Arduino Sketch Example: compound operator
//Date: 2015.1.25
//Auther: easy labo
//Example
a++; // return a, then a = a + 1
++a; // a = a + 1, then return a
a--; // return a, then a = a - 1
--a; // a = a + 1, then return a
a += b; // a = a + b
a -= b; // a = a - b
a *= b; // a = a * b
a /= b; // a = a / b
a &= b; // a = a & b
a |= b; // a = a | b“++”と”–“は、変数の前に記述するか後に記述するかで戻り値が変わるので、注意が必要です。
Sponsored Link
