7/2/11

Operators

Operators and Expressions
An Operator is a symbol used to do some operations. The operator instructs the computer to do some operation on the operand (data).

C programming language provides several operators to perform different kind to operations.
Types of Operators:
Arithmetic Operators: Arithmetic Operators are used to perform arithmetic operations such as Addition, Subtraction, Multiply, Division and Modules. 
Operator Name             Meaning             Syntax/Example
+                                  Addition                      a + b
-                                   Subtraction                  a – b
*                                  
 Multiply                       a * b
/                                   
 Division                       a / b
%                                 
 Modules                     a % b

Relational Operator / Comparison Operators: 
These Operators are used to do comparison on two operands.
Operator Name              Meaning                               Syntax/Example
<                                    Less than                                  a < b
>                                    Greater than                              a > b
<=                                  Less than or Equal to                a <= b
>=                                  Greater than or Equal to            a >= b
<>                                  Not Equal to                              a != b


Logical Operators:
Operator Name             Meaning                    Syntax/Example

&&                                   Logical AND               a > b && a > c
||                                       Logical OR                   a > b || a > c
!                                       
 Logical NOT                 ! a=10

Assignment Operators: 
C Language has several assignment operators - One simple assignment operator and Several Convenience assignment operators that combine arithmetic or bitwise operations with assignment. The operators are as follows:

Operator Name         Meaning             Syntax/Example
         =                     
 Assignment
       *=                     
 Multiply and assign
       /=                       Divide and assign
     %=                      Modulo and assign
      +=                      Add and assign
       -=                     
 Subtract and assign
       <<=                   Bitwise left shift and assign
       >>=                  
 Bitwise right shift and assign
      &=                    
 Bitwise AND and assign
      ^=                     
 Bitwise XOR and assign
       |=                     
 Bitwise OR and assign


1. Arithmetic Operators

There are operators for assignment, arithmetic functions, logical functions and many more. These operators generally work on many types of variables or constants, though some are restricted to work on certain types. Most operators are binary, meaning they take two operands. A few are unary and only take one operand.