News Ticker

# Arduino – Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −

• Arithmetic Operators
• Comparison Operators
• Boolean Operators
• Bitwise Operators
• Compound Operators

## Arithmetic Operators

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

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
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

## Comparison Operators

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

Operator name Operator simple Description Example
equal to == Checks if the value of two operands is equal or not, if yes then condition becomes true. (A == B) is not true
not equal to != Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. (A != B) is true
less than < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true
greater than > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true
less than or equal to <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true
greater than or equal to >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true

## Boolean Operators

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

Operator name Operator simple Description Example
and && Called Logical AND operator. If both the operands are non-zero then then condition becomes true. (A && B) is true
or || Called Logical OR Operator. If any of the two operands is non-zero then then condition becomes true. (A || B) is true
not ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. !(A && B) is false

## Bitwise Operators

Assume variable A holds 60 and variable B holds 13 then −