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

  1. Arithmetic Operators
  2. Compound Operators
  3. Boolean Operators
  4. Comparison Operators
  5. Bitwise Operators

Arithmetic Operators

Operator nameOperator symbolDescription
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.





int b; 

int c; 

int d; 

void setup ( )  

{  

Serial.begin( 9600 );  

}  

void loop ( )  

{  

b = 5;  

c = 5; 

d= b +c; 

Serial.println(b);   

}  





Comparison Operators

are used to compare the value of one variable with the other.

Operator nameOperator symbolDescription
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 nameOperator symbolDescription
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

Popular posts from this blog

Arduino function libraries~Math Library Function

Project Four: Pattern, Blink 4 leds using Arduino board

Project 6: Arduino print hello