Operators are symbols that tell the compiler to perform specific mathematical or logical manipulations. In this tutorial , we will try to cover the most commonly used operators in programming.
First, let's categorize them:
1. Arithmetic
2. Relational
3. Bitwise
4. Logical
5. Assignment
6. Increment
7. Miscellaneous
Arithmetic Operators:
Symbol | Operation | Usage | Explanation |
+ | addition | x+y | Adds values on either side of the operator |
- | subtraction | x-y | Subtracts the right hand operand from the left hand operand |
* | multiplication | x*y | Multiplies values on either side of the operator |
/ | division | x/y | Divides the left hand operand by the right hand operand |
% | modulus | x%y | Divides the left hand operand by the right hand operand and returns remainder |
Relational Operators: These operators are used for comparison. They return either true or false based on the comparison result. The operator '==' should not be confused with '='. The relational operators are as follows:
Symbol | Operation | Usage | Explanation |
== | equal | x == y | Checks if the values of two operands are equal or not, if yes then condition becomes true. |
!= | not equal | x != y | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. |
> | greater than | x > y | Checks if the value of the left operand is greater than the value of the right operand, if yes then condition becomes true |
< | less than | x < y | Checks if the value of the left operand is less than the value of the right operand, if yes then condition becomes true. |
>= | greater than or equal | x >= y | Checks if the value of the left operand is greater than or equal to the value of the right operand, if yes then condition becomes true. |
Chủ Đề |