An operator is the symbol that tells the compiler to perform
mathematical or logical operations. There are different kinds of operators is
given below:
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc. Operators
Arithmetic Operators
– 
If a=10,b=5
| 
   
Operator 
 | 
  
   
Description 
 | 
  
   
Example 
 | 
 
| 
   
         + 
 | 
  
   
Adds Tow operands 
 | 
  
   
a+b=15 
 | 
 
| 
   
        -  
 | 
  
   
Subtract second to first operands 
 | 
  
   
a-b=5 
 | 
 
| 
   
        * 
 | 
  
   
Multiply Both operands 
 | 
  
   
a * b=50 
 | 
 
| 
   
        / 
 | 
  
   
Divided numerator by de-numerator 
 | 
  
   
a/b=2 
 | 
 
| 
   
       % 
 | 
  
   
Reminder after integer division 
 | 
  
   
a%b=0 
 | 
 
| 
   
      ++ 
 | 
  
   
Increase integer value one by one 
 | 
  
   
a++=11 
 | 
 
| 
   
     -- 
 | 
  
   
Decrease integer value one by one 
 | 
  
   
a--=9 
 | 
 
Relational operators-
 If A=10, B=5
| 
   
Operator 
 | 
  
   
Description 
 | 
  
   
Example 
 | 
 
| 
   
== 
 | 
  
   
Checks the value of two operands is equal or not 
 | 
  
   
A==B(it is not true) 
 | 
 
| 
   
!= 
 | 
  
   
Checks the value of two operands is not equal 
 | 
  
   
A!=B(It is true) 
 | 
 
| 
   
>  
 | 
  
   
Checks the value of left operand is greater than value of right
  operand 
 | 
  
   
A>B(It is true) 
 | 
 
| 
   
<  
 | 
  
   
Checks the value of left operand is greater than value of right
  operand 
 | 
  
   
A<B(It is not true) 
 | 
 
| 
   
>= 
 | 
  
   
Checks the value of left operand is greater than or equal to the
  value of right operand 
 | 
  
   
A>=B(It is true) 
 | 
 
| 
   
<= 
 | 
  
   
Checks the value of the left operand is less than or equal to the value
  of right operand 
 | 
  
   
A<=B(it is not true) 
 | 
 
Logical operator-
| 
   
Operator 
 | 
  
   
Description 
 | 
  
   
Example 
 | 
 
| 
   
&& 
 | 
  
   
It is called AND operator the condition becomes true if both operand
  are non-zero 
 | 
  
   
A&&B (false) 
 | 
 
| 
   
|| 
 | 
  
   
It is called OR operator the condition becomes true if any of the two
  operand is non-zero 
 | 
  
   
A||B(true) 
 | 
 
| 
   
! 
 | 
  
   
`it is called Logical NOT operator, if the condition is true then
  Logical NOT operator will make false 
 | 
  
   
!(A&&B) true 
 | 
 
Bitwise Operator
- 
Bitwise operator work on the bit, the truth table for &,
|, ^ is given below:
| 
   
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 
 | 
 
Assignment Operator
– 
| 
   
Operator 
 | 
  
   
Description 
 | 
  
   
Example 
 | 
 
| 
   
= 
 | 
  
   
Use to assign the values from right side operand to left side operand 
 | 
  
   
C=A+B assign the value of A+B to C 
 | 
 
| 
   
+= 
 | 
  
   
It adds right operand to left Operand and assign the value(result) to
  the left operand 
 | 
  
   
A+=B is equal to A=A+B 
 | 
 
| 
   
-= 
 | 
  
   
It subtract right operand from left operand and assign the result to left
  operand 
 | 
  
   
A-=B is equal to A=A-B 
 | 
 
| 
   
*= 
 | 
  
   
It multiply right operand to left operand and assign the value to
  left operand 
 | 
  
   
A*=B is equal to A=A*B 
 | 
 
| 
   
/= 
 | 
  
   
It divides right operand to left operand and assign the value to left
  operand 
 | 
  
   
A/=B is equal to A=A/B 
 | 
 
| 
   
%= 
 | 
  
   
It is used to find the modulus of two operand the assign the value to
  the left operand 
 | 
  
   
C%=A is equal to C=C%A 
 | 
 
| 
   
<<== 
 | 
  
   
Left shift AND assignment operator 
 | 
  
   
A<<==2 is equal to A=A<<==2 
 | 
 
| 
   
>>== 
 | 
  
   
Right shift AND assignment operator 
 | 
  
   
A>>==2 is equal to A=A>>==2 
 | 
 
| 
   
&= 
 | 
  
   
It is called Bitwise AND assignment operator 
 | 
  
   
A&=2 is equal to A=A&2 
 | 
 
| 
   
^= 
 | 
  
   
It is called bitwise exclusive OR and assignment operator 
 | 
  
   
A ^=2 is equal to A=A ^2 
 | 
 
| 
   
|= 
 | 
  
   
It is called bitwise inclusive OR and assignment operator 
 | 
  
   
A|=2 is equal to A=A|2 
 | 
 
Miscellaneous operator
– 
| 
   
Operator 
 | 
  
   
Description 
 | 
  
   
Example 
 | 
 
| 
   
Sizeof() 
 | 
  
   
It return the size of a data type 
 | 
  
   
Sizeof(int), return 4 
 | 
 
| 
   
typeof() 
 | 
  
   
It return the type of class 
 | 
  
   
Typeof(StreamReader); 
 | 
 
| 
   
& 
 | 
  
   
Return the address of an variable 
 | 
  
   
&a 
 | 
 
| 
   
* 
 | 
  
   
Pointer to variable 
 | 
  
   
*a 
 | 
 
| 
   
?: 
 | 
  
   
Conditional Expression 
 | 
  
   
If condition is true? Then value of X otherwise value of Y 
 | 
 
No comments:
Post a Comment