Wednesday, 31 July 2013

Q: What is Operator ?


Operator:
                
Operator is a system defined symbol which works on some values or expressions and return another value .
  ex-  3+4 is equal to seven,here 3 and 4 are operand
and '+' is operator.
'C' language has rich library of operator category.
Some operators are:-

  1. Assignment Operator
  2. Arithmethic Operator
  3. Relational Operator
  4. Logical Operator
  5. Increment Operator
  6. Decrement Operator
  7. Bitwise Operator
  8. Size of() Operator 
 
1. Assignment Operator (=) :  It is used to assign the value of expression of right hand side to a storage space on left hand side.
'C' language support short hand assignment operator.


Operator

 Expression
 Assignment Operator
+ =

X= X+Y
  X += Y
- =
X= X-Y 
X -= Y

 * =
X= X*Y
X *= Y

 / =
X= X/Y
X /= Y 

 % =

X=X%Y
X %= Y  
2. Arithmetic Operator :- Arithmetic operator returns a value after working on some expression.These operator works on two operand
Operator          

+

-

*

/

%
Operation

Addition

Subtraction

Multipication

Division

Remainder
3.Relational Operator :  Relational operator compares two value of an expression and return true or false dependind upon the comparison.
some relational operator are:    <,<=, >, >=, == , !=

Logical Operators

Logical operators are used to combine expressions containing relation operators. In C, there are 3 logical operators:
- See more at: http://www.programiz.com/c-programming/c-operators#logical

Logical Operators

Logical operators are used to combine expressions containing relation operators. In C, there are 3 logical operators:
- See more at: http://www.programiz.com/c-programming/c-operators#logical
4.Logical Operator :- 
                       There are 3 logical operators:
||  logical OR
&&  logical AND
!  logical Not

a. Logical OR operator(||) :-    This operator also known as short-circuit logical OR operator. This operator check two conditions. It worrks ,if one or all two condition true than result true , otherwise result false.
Operand 1

 Operand 2

 Operand 1 || Operand 2

 False
False

False

False
True
True

 True

 False
 True
 True
 True

 True
b. Logical AND Operator(&&) :-  This operator also known as short-circuit logical && operator.This operator check two conditions. It works, if all conditions true than result true , otherwise result false.
Operand 1
 Operand 2
 Operand 1 && operand 2
True
  True
 True
True
  False
  False
False
True
  False
 False
 False
 False
c.Logical NOT Operator (!) :-    It is a unary Operator .
Operand 1
 Operand 2
False
 True
 True
 False
5.Increment Operator (++) :-    Increment Operator increase the value  of the variable by one .

Expression        Operator
X=X+1                 X++
X=1+X                 ++X
6. Decrement Operator (--) :-  Decrement Operator decrease the value of the variable by one

Expression        Operator
X=X-1                 X--
X=1-X                 --X
7.Bitwise Operator :-  Bitwise operator is used to manipulate data at binary level.
                                                    They are used to certain operation faster .
                                                    All bitwise operator works only on integers or character type data.

   'C' Support following bitwise operator.
a. Bitwise Logical Operator :- 
Operator              Meaning
   &                      Bitwise  AND     
   |                        Bitwise  OR
   ^                        Bitwise  XOR
b. Bitwise Shift Operator :- 

Operator               Meaning
  >>                        Right Shift
  <<                        Left Shift
c. Bitwise One's Complement Operator :-
Operator               Meaning
    
                  one's complement
8. Sizeof()  Operator:-     The sizeof operator returns the size of its operand in bytes. The sizeof operator always precedes its operand. The operand may be an expression or it may be a cast.
Example:

            Suppose i is an integer variable and c is a character type variable then

Printf(“Size of integer : %d”,sizeof(i));
Printf(“Size of character : %c”,sizeof(c));
Might generate the following output :
Size of integer : 2
Size of character : 1
Click to edit your
Website Header.
Drag to Move

No comments:

Post a Comment