OPERATORS IN C

OPERATORS IN C

OPERATOR:- It is a symbol which performs a particular operation

OPERAND:- It is an entity on which an operator acts.

UNARY OPERATOR:- It requires only a single operand.

BINARY OPERATOR:- It requires two operands.

'C' operators can be classified into a number of categories. They are

          1) ARITHMETIC OPERATORS
          2) RELATIONAL OPERATORS
          3) LOGICAL OPERATORS
          4) ASSIGNMENT OPERATORS
          5) INCREMENT/DECREMENT OPERATORS
          6) BITWISE OPERATORS
          7) SPECIAL OPERATORS
            A) TERMINARY OPERATORS
            B) COMMA OPERATOR
            C) SIZEOF OPERATOR

1)ARITHMATIC OPERATOR

These are the basic operators in c language. These are used for  arithmetic operations.

  + :  addition
  -  :  subtraction
  * :  multiplication
  /  :  division
  % :  modulus(remainder)

2) RELATIONAL OPERATOR

These are used to test the relation between two values or two expressions.

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

3) LOGICAL OPERATORS

It is used to combine result of two or more expressions

  &&     :      logical and

  ||          :     logical or

  !           :    logical not

4) ASSIGNMENT

It is used to assign a value or the value of on expression to an identifier.
Symbol:

=    :    assignment operator

Compound assignment operator or shorthand assignment operator:

+=
-=
*=
/=
%=

5) INCREMENT/DECREMENT OPERATOR

          These are used to control the loops in an efficient method.

INCREMENT OPERATOR

          The symbol ++ is used for increment by 1

          ++identifier-------->prefix increment

          identifier++-------->postfix increment

Example:-
          int n=10;
          ++n (or) n++;
          n=11;

          prefix:-
                       int a=10,b;
                       b=++a;
                       a--->11
                       b--->11

          postfix:-
                       int a=10,b;
                       b=a++;
                       a---->11
                       b---->10

DECREMENT OPERATOR

          The symbol -- is used for decrement by 1

          --identifier      ------->prefix decrement

          identifier--      -------->postfix decrement

Example:-
          int n=10;
          --n (or) n--;
          n=9;

          prefix:-
                      int a=10,b;
                      b=--a;
                      a=9
                      b=9

          postfix:-
                      int a=10,b;
                      b=a--;
                      a=9
                      b=10

6) BITWISE OPERATORS

These are used for manipulation of data of at bit level. These operators are classified into two types namely:-

  1) BITWISE LOGICAL OPERATORS
  2) BITWISE SHIFT OPERATORS

BITWISE LOGICAL OPERATOR

These operators are used the bitwise logical decision making

&      :    bitwise logical and
|        :    bitwise logical or
^       :    bitwise logical xor     (x-exclusive)

7) SPECIAL OPERATOR

A) TERINARY OPERAOTR  (OR) CONDITIONAL OPERATOR

          A terinary operator pair ? : is available in the c language .It is used to construct a conditional expression.
          The general form of the terinary operator:
          exp1? exp2: exp3;

          If exp1 is true then exp2 is evaluated and its value becomes value of the expression otherwise exp1 is false then exp3 is evaluated  and its value becomes value of expression.

B) COMMA OPERATOR

          It can be used the link the related expressions together.
The general form of the comma operator is:-

Example:-
                  int a,b,c;
                  c=(a=10,b=20,a+b);
                  a=10;
                  b=20;
                  c=10;
C) SIZEOF OPERATOR

It is a compile time operator and is used to get the memory size of specified variable or expression or datatype.

  Syntax:-
               (var (or) exp (or) datatype);
Example:-

               sizeof(int)------->2 bytes
               sizeof(char)------>1 byte
               sizeof(float)----->4 bytes
               sizeof(double)---->8 bytes