Operators
Operators
Types of operators
Arithmetic Operators
|
Operator |
|
|
+ |
Addition |
|
- |
Subtraction |
|
* |
Multiplication |
|
/ |
Division |
|
% |
Modulus |
Relational Operators
|
Operator |
Description |
|
== |
Is equal to |
|
!= |
Is not equal to |
|
> |
Greater than |
|
< |
Less than |
|
>= |
Greater than or equal to |
|
<= |
Less than or equal to |
Logical Operators
|
Operator |
description |
Example |
|
&& |
Logical AND operator. If both
the operands are non-zero, then the condition is true. |
(A && B) is false |
|
|| |
Logical OR operators. If any of these
two operands is non-zero, the condition became true. |
(A || B) is true |
|
! |
Logical NOT operator. It is used
to reserve the logical state of its operand. If condition is true, then
Logical NOT operator will make it false. |
!(A && B) is true |
Bitwise Operators
|
a |
b |
A & b |
A | b |
A ^b |
|
0 |
0 |
0 |
0 |
0 |
|
0 |
1 |
0 |
1 |
1 |
|
1 |
1 |
1 |
1 |
0 |
|
1 |
0 |
0 |
1 |
1 |
Other bitwise operators
Assignment Operators
|
operator |
Description |
|
= |
Single assignment operator. Assign
values from right side operand |
|
+= |
Add AND assignment operator. It adds
the right to left operand and assigned the result to the left operand. |
|
-= |
Subtract AND assignment operator.
It adds the right to left operand and assigned the result to the left operand. |
|
*= |
|
|
/= |
Miscellaneous operators
|
Operator |
Description |
Example |
|
Sizeof() |
Return the size of variable |
Will return int’s size |
|
& |
Returns the address of variable |
Returns the actual address of variable |
|
* |
Pointer to variable |
*a: |
|
?: |
Conditional expression |
If condition true(X) Otherwise(Y) |
Operator precedence in C
|
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 |
Comments
Post a Comment