Arduino – Arithmetic Operators

Arithmetic Operators

In this guide, we will discuss Arithmetic Operators examples.

Assume variable A holds 10 and variable B holds 20 then −

Operator nameOperator simpleDescriptionExample
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 operandsA + B will give 30
subtractionSubtracts second operand from the firstA – B will give -10
multiplication*Multiply both operandsA * B will give 200
division/Divide numerator by denominatorB / A will give 2
modulo%Modulus Operator and remainder of after an integer divisionB % A will give 0

Example

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

Result

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

Previous Page:-Click Here

Leave a Reply