Operators | Description | Example |
+ | Adds two operands | a+b = 15 |
- | Subtracts second from the first operand | a-b = 5 |
* | Multiplies both the operands | a*b = 50 |
/ | Divides numerator by denominator | a / b = 2 |
% | Remainder of an integer division | a % b = 0 |
++ | Increment the value by 1 | a++ = 11 |
-- | Decrement the value by 1 | a-- = 9 |
Operator | Description | Example |
== | Returns true only if the value of two operands are equal | (a == b) is not true |
!= | Returns true only if the value of two operands are not equal | (a != b) is true |
> | Returns true if the value of left operand is greater than right operand | (a > b) is true |
< | Returns true if the value of left operand is lesser than right operand | (a < b) is not true |
>= | Returns true if the value of left operand is greater than or equal to the right operand | (a >= b) is true |
<= | Returns true if the value of left operand is lesser than or equal to the right operand | (a <= b) is not true |
Operator | Name | Description | Example |
|| | Logical OR | Returns true if one of the statement is true | A || B is TRUE |
&& | Logical AND | Returns true if both the statements are true | A && B is FALSE |
! | Logical NOT | Returns true if the statement is false (Reverse the result) | !(A || B) is FALSE |
p | q | p | q | p & q | p ^ q |
0 | 0 | 0 | 0 | 0 |
0 | 1 | 1 | 0 | 1 |
1 | 0 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 0 |
Operator | Name | Description | Example |
| | Logical OR | Returns 1 if any one of the bit is 1 | A|B = 61 => 0011 1101 |
& | Logical AND | Returns 1 if only both the bits are 1 | A & B = 12 = > 0000 1100 |
^ | Logical XOR | Returns 1 if only either of the bit is 1 | A ^ B = 49 => 0011 0001 |
~ | One’s Complement Operator | This is a unary operator and has the effect of ‘flipping bits’ | (~A) = ~(60) => -1100 0011 = -195 |
<< | Left Shift Operator | The left operand value is shifted left by the number of bits specified by the right operand | A << 2 = 1111 0000 = 240 |
>> | Right Shift Operator | The left operand value is shifted right by the number of bits specified by the right operand | A >> 2 = 0000 1111 = 15 |
Operator | Description | Example |
= | This is a Assignment Operator which assigns the values from right operand to the left operand | C = A + B, the value of A+B is assigned to the left operand C |
+= | This adds the right operand to the left operand and assigns the value to the left operand | B += A, the value of B+A is assigned to the left operand B |
-= | This subtracts the right operand from the left operand and assigns the value to the left operand | B -= A, the value of B-A is assigned to the left operand B |
*= | This multiplies the right operand to the left operand and assigns the value to the left operand | B *= A, the value of B*A is assigned to the left operand B |
/= | This divides the left operand with the right operand and assigns the value to the left operand | B /= A, the value of B/A is assigned to the left operand B |
%= | This takes the modulus using two operands and assign the result to the left operand | B %= A, the value of B%A is assigned to the left operand B |
<<= | Left shift and assigned to the left operand | A<<=2, the value of A<<2 is assigned to the left operand A |
>>= | Right shift and assigned to the right operand | A >>= 2, the value of A>>2 is assigned to the left operand A |
&= | This performs bitwise AND and assigns the value to the right operand | A &= 2, the value of A&2 is assigned to the left operand A |
|= | This performs bitwise Or and assigns the value to the right operand | A |= 2, the value of A|2 is assigned to the left operand A |
^= | This performs bitwise XOR and assigns the value to the right operand | A ^= 2, the value of A^2 is assigned to the left operand A |
Operator | Description | Example |
sizeof() | Returns the size of a variable | sizeof(A); the size of the variable A is 4 |
& | Returns the address of the variable | &A; returns the actual address of the variable |
* | Pointer to a variable | *A; |
?: | Conditional Expression | X>Y?X:Y. If Condition is true? Then value X otherwise value Y |
Category | Operator | Associativity |
Postfix | () [] -> . ++ -- | Left to Right |
Unary | + - ! ~ ++ -- (type)* & sizeof | Right to Left |
Multiplicative | */ % | Left to Right |
Additive | + - | Left to Right |
Shift | << >> | Left to Right |
Relational | < <= > >= | Left to Right |
Equality | == != | Left to Right |
Bitwise AND | & | Left to Right |
Bitwise XOR | ^ | Left to Right |
Bitwise OR | | | Left to Right |
Logical AND | && | Left to Right |
Logical OR | || | Left to Right |
Conditional | ?: | Right to Left |
Assignment | = += -= *= /= %= >>= <<= &= ^= |= | Right to Left |
Comma | , | Left to Right |