Arduino Operators
Arduino Operators
The operators are used to solve logical and mathematical problems. C language is rich in built-in operators and provides the following types of operators.
They are classified:-
- Arithmetic Operators
- Compound Operators
- Boolean Operators
- Comparison Operators
- Bitwise 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. | |
addition | + | Adds two operands | |
subtraction | - | Subtracts second operand from the first | |
multiplication | * | Multiply both operands | |
division | / | Divide numerator by denominator | |
modulo | % | Modulus Operator and remainder of after an integer division |
Consider the below code.
Comparison Operators
are used to compare the value of one variable with the other.
Operator name | Operator symbol | Description | |
---|---|---|---|
equal to | == | Checks if the value of two operands is equal or not, 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. | |
less than | < | Checks if the value of the left operand is less than the value of right operand, if yes then condition becomes true. | |
greater than | > | Checks if the value of the 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 the left operand is less than or equal to the value of right operand, if yes then condition becomes true. | |
greater than or equal to | >= | Checks if the value of the left operand is greater than or equal to the value of right operand, if yes then condition becomes true. |
Example, (You can copy the code below to test if it's working)
Example:
int b, c; //defining variables
void setup ( )
{
Serial.begin( 9600 );
}
void loop ( )
{
b = 4; // assign
c = 9; // assign
if ( b < 4 )
Serial.println(b);
if ( c < 4)
Serial.println( c);
}
Boolean Operators
are NOT ( ! ), Logical AND ( & & ), and Logical OR ( | | ).
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. |
Bitwise Operators
The Bitwise operators operate at the binary level.
Comments
Post a Comment