Operator | Meaning | Example | Result |
---|---|---|---|
+ | addition | 5+2 | 7 |
- | subtraction | 5-2 | 3 |
* | multiplication | 5x2 | 10 |
/ | division | 5/2 | 2 |
% | modulus operator to get remainder in integer division | 5 % 2 | 1 |
Operator | Meaning | Example | Result |
---|---|---|---|
< | less than | 5<2 | false |
> | greater than | 5>2 | true |
<= | less than or equal to | 5<=2 | false |
>= | greater than or equal to | 5>=2 | true |
== | equal to | 5==2 | false |
!= | not equal to | 5!==2 | true |
Operator | Meaning | Example | Result |
---|---|---|---|
&& | logical and | (5<2)&&(5>3) | false |
|| | logical or | (5<2)||(5>3) | true |
! | logical not (negation) | !(5<2) | true |
Note : logical not(!) is unary operator which requires only one operand (true to false and vice versa).
Increment operator (++) is used to increase the value of an integer or char variable.
Decrement operator (--) is used to reduce the value of an integer or char variable.
m = 15;
m++ or ++m will produce the result m = 16.
m = 15;
m-- or --m will produce the result m = 14.
Note : That m++ and m-- are referring the post-fix increment and decrement operation, and ++m and --m are referring the prefix increment and decrement operation.
Operator | Meaning | Example | Result |
---|---|---|---|
+= | m += 10 | m = m + 10 | 25 |
-= | m -= 10 | m = m - 10 | 5 |
*= | m *= 10 | m = m * 10 | 150 |
/= | m /= 10 | m = m / 10 | 1 |
%= | m %= 10 | m = m % 10 | 5 |
Conditional operator is used to check a condition and select a value depending on the condition. Normally the selected value will be assigned to a variable which ha the following form.
variable = (condition) ? value 1 : value 2;
When this operator is execute by the computer, the value of the condition is evaluated. If it is true then value 1 is assigned to the variable, otherwise value 2 is assigned to the variable.
Consider the following example.
big = ( a > b ) ? a : b
In this operation, the computer checks the value of the condition (a>b); If it is true a is assigned to big; otherwise b is big.
Conditional operator, like assignment operators, is also more concise and more efficient.
Operator | Meaning |
---|---|
<< | shifts the bits to left |
>> | shifts the bits to right |
~ | bitwise inversion (one's complement) |
& | bitwise logical and |
| | bitwise logical or |
^ | bitwise exclusive or |
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.