Arduino-arithmetic-operators

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

Arduino-算術演算子

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

Operator name Operator simple Description Example
assignment operator = Stores the value to the right of the equal sign in the variable to the left of the equal sign. A = B
addition + Adds two operands A + B will give 30
subtraction - Subtracts second operand from the first A - B will give -10
multiplication * Multiply both operands A* B will give 200
division / Divide numerator by denominator B/A will give 2
modulo % Modulus Operator and remainder of after an integer division B % A will give 0

void loop () {
   int a = 9,b = 4,c;
   c = a + b;
   c = a - b;
   c = a *b;
   c = a/b;
   c = a % b;
}

結果

a + b = 13
a - b = 5
a* b = 36
a/b = 2
Remainder when a divided by b = 1