Mathematical Operators are widely used in programming in case of problem solving; calculations will always be used for performing numerous tasks. The main mathematical operators are:
+ (Sum)
– (subtraction)
* (multiplication)
/ (division)
It is very important to know that, as in mathematics, operations in programming logic follow an order. There is an order of precedence between these operators:
- First: () – parentheses;
- Second, * (multiplication) and / (division), the one that first appear;
- Third: + (sum) or – (minus), the one that first appear.
Relational operators are used to compare two values that can be variable or constant, of the same type. Examples of relational operators:
- = (less than)
- > (greater than)
- <(less than)
- <> (different from)
- > = (greater than or equal to)
- <= (less than or equal to)
These operators are often used and the result of these comparisons implies a logical value (true or false):
10> = 5 (true)
11 <> 11 (false)
0.5 <(-1) (false)
The A = (true)
Finally, the logical operators are combined to the expressions. Thus we got a true or false value. The main logical operators are:
- AND – conjunction
- Or – disjunction
- No – denial
The “E” and “or” are binary operators. This means that they serve to combine two expressions. The “No” is a unary operator. This means that it serves to change the value of an expression. To better understand how they are used, see the following expressions:
- Has electricity;
- The computer is plugged in.
So that the computer turns on, you have to obey the two previous expressions. Imagine the following relationship:
(Expression 1) and (Expression 2)
If one of these expressions is not true, the condition is false (The computer does not start). The computer turns on only if both are true. The possibilities table of a condition is called Truth Table:
Expression 1 and Expression 2
FALSE FALSE FALSE
FALSE FALSE TRUE
TRUE FALSE FALSE
TRUE TRUE TRUE
The logical operators can be combined in countless ways. As mathematical, logical operators follow an order of precedence (priority):
- () – Parentheses.
- No – Denial.
- E – Conjunction.
- Or – disjunction
Visit our blog and check out more content!
You might also like…