Relation Operators:
The following table shows all relation operators supported by any programming language.
Operator | Description |
== (equal to) | Check if the two operands are equal. |
!= (not equal to) | Check if the two operands are not equal. |
> (greater than) | Check if the operand on the left is greater than the operand on the right. |
< (less than) | The check operand on the left is smaller than the right operand. |
>= (greater than or equal to) | Check left operand is greater than or equal to the right operand. |
<= (less than or equal to) | Check if the operand on left is smaller than or equal to the right operand. |
For example, assume variable A holds 10 and variable B holds 20, then:
Operator | Description | Example |
== | Checks if the values of two operands are equal or not, if yes then the condition becomes true. | (A == B) is not true. |
!= | Checks if the values of two operands are equal or not, if values are not equal then the condition becomes true. | (A != B) is true. |
> | Checks if the value of the left operand is greater than the value of the right operand, if yes then the condition becomes true. | (A > B) is not true. |
< | Checks if the value of the left operand is less than the value of the right operand, if yes then the condition becomes true. | (A < B) is true. |
>= | Checks if the value of the left operand is greater than or equal to the value of the right operand, if yes then the condition becomes true. | (A >= B) is not true. |
<= | Checks if the value of the left operand is less than or equal to the value of the right operand, if yes then the condition becomes true. | ( A =< B) is true. |
Logical Operators:
The following table shows all logical operators supported by any programming language.
Operator | Description |
&& (logical and) | Called Logical AND operator. |
I (logical or) | Called Logical OR Operator. |
! (logical not) | Called Logical NOT Operator. |
For example, Assume Boolean variable A holds true and variable B holds false, then
Operator | Description | Example |
&& | If both operands are non-zero, then the condition becomes true. | (A && B) is false |
II | If any of the two operands is non-zero, then the condition becomes true. | (A I I B) is true |
! | Use to reverse the logical state of its operand. If a condition is true then the logical NOT operator will make false. | !(A && B) is true |
Bitwise Operators:
Any programming language defines several bitwise operators that can be applied to the integer types long, int, short, char and byte.
Operator | Description |
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise exclusive OR |
<< | left shift |
>> | right shift |
Now let’s see the truth table for bitwise &, I and ^
a | b | a & b | a | b | a ^ b |
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 0 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
The bitwise shift operators shift the bit value. The left operand specifies the value to be shifted and the right operand specifies the number of positions that the bits in the value that are to be shifted. Both operands have the same precedence. Example,
a = 0001000
b = 2
a << b = 0100000
a >> b = 0000010
Assignment Operators:
Which can be used to assign a value to a variable. The following table shows all assignment operators supported by any programming language.
Operator | Description | Example |
= | assigns values from right-side operands to left-side operands | a = b |
+= | adds the right operand to the left operand and assigns the result to left | a += b is same as a = a + b |
-= | subtracts the right operand from the left operand and assigns the result to the left operand | a -= b is same as a = a – b |
*= | multiply the left operand with the right operand and assign the result to the left operand | a *= b is same as a = a * b |
/= | divides the left operand with the right operand and assigns the result to the left operand | a /= b is same as a = a / b |
%= | calculate modulus using two operands and assign the result to the left operand | a %= b is same as a = a % b |
Let’s suppose variable A holds 8 and B holds 3.
Operator | Example | Result |
+= | A += B o r A = A + B | 11 |
-= | A -= 3 or A = A + 3 | 5 |
*= | A *= 7 or A = A * 7 | 56 |
/= | A /= B or A = A / B | 2 |
%= | A %= 5 or A = A % 5 | 3 |
a=b | Value of b will be assigned to a |