An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. The coding language that is used by Arduino is rich in built-in operators and provides the following types of operators
Arithmetic Operators
Operator name | Operator Symbol | Description |
---|---|---|
assignment operator | = | Stores the value to the right of the equal sign in the variable to the left of the equal sign. |
substraction | - | Subtracts second operand from the first |
addition | + | Adds two operands |
Devision | / | Divide numerator by denominator |
Multiplier | * | Multiply both operands |
Arithmetic Operators Code
int x = 5 int y = 4 int z = 0 x + y = 9 z = x + y // the variable z will now hold the number 9 x - y = 3
Comparison Operators
Operator Name | Operator Symbol | Description |
---|---|---|
equal to | == | Checks if the value of two operands is equal or not, if yes then condition becomes 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. |
greater than | > | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes 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. |
less than | < | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. |
not equal to | != | Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. |
Comparison Operators
int x = 5 int y = 4 int z = 0 x == y; // this will return the value False x != y; // this will return the value True
Compound Operators
Operator Name | Operator Symbol | Description |
---|---|---|
increment | ++ | Increment operator, increases integer value by one |
decrement | -- | Decrement operator, decreases integer value by one |
compound addition | += | Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand |
compound substraction | -= | Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand |
compound multiplier | *= | Multiply AND assignment operator. It multiplies right operand with the left operand and assign the result to left operand |
compound devider | /= | Divide AND assignment operator. It divides left operand with the right operand and assign the result to left operand |
Bitwise Operators
Operator Name | Operator Symbol | Description |
---|---|---|
and | & | Binary AND Operator copies a bit to the result if it exists in both operands. |
or | | | Binary OR Operator copies a bit if it exists in either operand |
xor | ^ | Binary XOR Operator copies the bit if it is set in one operand but not both. |
not | ~ | Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. |
shift left | << | Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. |
shift right | >> | Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. |
Boolean Operators
Operator Name | Operator Symbol | Description |
---|---|---|
and | && | Called Logical AND operator. If both the operands are non-zero then then condition becomes true. |
or | || | Called Logical OR Operator. If any of the two operands is non-zero then then condition becomes 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. |