Arduino-compound-operators

提供:Dev Guides
移動先:案内検索

Arduino-複合演算子

変数Aが10を保持し、変数Bが20を保持すると仮定します-

Operator name Operator simple Description Example
increment ++ Increment operator, increases integer value by one A++ will give 11
decrement  —  Decrement operator, decreases integer value by one A-- will give 9
compound addition += Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand B = A is equivalent to B = B A
compound subtraction -= Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand B -= A is equivalent to B = B - A
compound multiplication *= Multiply AND assignment operator. It multiplies right operand with the left operand and assign the result to left operand B*= A is equivalent to B = B *A
compound division /= Divide AND assignment operator. It divides left operand with the right operand and assign the result to left operand B/= A is equivalent to B = B/A
compound modulo %= Modulus AND assignment operator. It takes modulus using two operands and assign the result to left operand B %= A is equivalent to B = B % A
compound bitwise or = bitwise inclusive OR and assignment operator
A = 2 is same as A = A 2 compound bitwise and

void loop () {
   int a = 10,b = 20
   int c = 0;

   a++;
   a--;
   b += a;
   b -= a;
   b* = a;
   b/= a;
   a %= b;
   a |= b;
   a &= b;
}

結果

a = 11
a = 9
b = 30
b = 10
b = 200
b = 2
a = 0
a = 0
a = 30