Wednesday, 14 March 2012

Operator in 'C', Arithmetic Operator, Relational Operator, Assignment Operator, Pointer Operator, Special Operator, Increment and Decrement Operator

An Operator is a symbol that indicate for some operation. An operator operates on variables and perform an action. Operator can perform action on value or variable. Value or variable on which operator take action is called operand. According to operand used by any operator.
            Operator is of three types-
                     

  • Unary Operator
  • Binary Operator
  • Ternary Operator

     Unary operator uses one operand.
     Binary operator uses two operand.
     Ternary operator uses three operand.


On the basis of action taken by operators, operator is of following types-



  1. Arithmetic Operator
  2. Relational Operators
  3. Logical Operators
  4. Assignment Operators
  5. pointer Operators
  6. Special Operators
  7. Bitwise Operators

  • Arithmetic Operator:-
                            An arithmetic operator is a symbol which performs an  arithmetic operation namely, addition, subtraction, multiplication, division etc. All the arithmetic operator is binary operator.

            Operator                                                                  Operation
              
             Addition                                                                          +
             Subtraction                                                                     -
             Multiplication                                                                  *
             Division                                                                           /
             Remainder                                                                     %


  • Relational Operator:-
                       Relational operator are used to compare values between two variables and thus form relational expressions. The logical or relational expressions give the value "1" for TRUE result and The value "0" for FALSE result.

           Relational Operator                                            Action

                        >                                                              greater than
                        >=                                                             greater than or equal
                        <                                                               less than
                        <=                                                             less than or equal
                        ==                                                             equal 
                        !=                                                              not equal

           
           Logical Operator                                                Action

                    &&                                                                   AND
                     ::                                                                      OR
                     !                                                                       NOT
                    

  • Assignment Operator:-
                    Equal sign (=) is assignment operator. The variable appearing on the left side of '='  sign and it is assigned the value appearing on the right side of this sign.


                 Syntax-   variable_name= expression ;
        
          The expression can be a single variable or literal, or a combination of variables, literals, and operators.

    Note:-   In 'C' shortcuts are possible:-
                  x-  = y               x = x-y ;
                  x* = y                x = x*y ;
                  x/ = y                x = x/y ;
                  x% = y              x = x%y ;
  

  • Pointer Operator:-
                       The pointer operators are the 'address-of' operator (&) and the indirection operator (*). The indirection operator is used to get the contents of the address operand pointing to a particular memory element. The (&) operator returns the address of the variable.


  • Special Operator:-
                   C also supports some special operators as conditional operator (?), the comma operator (,) and the size of operator.

      Note:-  The conditional operator (?:) helps in building a simple conditional expression.

      Syntax:-   expression_1?expression_2:expression3;


  • Increment and Decrement Operator:-
                  The increment and decrement operators are ++ And --, Both are unary operators. Increment operator increases one to its operand. 
                  Increment and decrement operator also can be divided in to pre-increment, post-increment (a++), pre-decrement (--a) and post-decrement (a--).


  • Bitwise Operator:-
                          Bitwise operators are:-

               Bitwise Operator                                              Meaning

                           &                                                                 AND
                           ::                                                                  OR
                           ^                                                                   XOR
                           ~                                                                   one's complement
                          >>                                                                 right shift
                          <<                                                                 left shift

No comments:

Post a Comment