````

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
addition + Adds two operands A + B will give 30
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

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









































Related Posts:

  • Arduino - Control Statements Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. It should be along with a statement or statements to be executed if the condition is determin… Read More
  • Arduino - If …else statement An if statement can be followed by an optional else statement, which executes when the expression is false. if … else Statement Syntax if (expression) { Block of statements; } else { Block of statements; } if…else … Read More
  • Arduino - 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 … Read More
  • 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… Read More
  • Arduino - If…else if …else statement The if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if...else if…else statements, keep in mind − An if … Read More

0 comments:

Post a Comment

 
Powered by Blogger