Thursday 16 May 2013

Operators in C++


Operator is a symbol that causes specific mathematical or logical manipulations to be performed. A combination of constants and variable together with the operators is called an expression .An expression that involves only constant is called constant expression .An expression that involves only arithmetic operators are called arithmetic expressions.

Eight types of operators :-

1.Arithematic Operators:
             +         Addition
-                      Subtraction
*           Multiplication
/           Division
%         Modulo Divison.

2. Relational operators:- used to make comparisons
           <     less than
>    greater than
<=  Less than or equal to
>= greater than or equal to
= = Equal to
!=   not equal to
  1. Logical operators:-logical operators && and || are used when more than one conditon are to be tested to make decision
&&             AND
||                OR
!                 NOT
  1. Assignment operators
=    equal to
C supports a set of shorthand assignment operators .Eg:+=, -=, *=, /= etc.
A=A+1 equals A+=1
S=S*(k+p)  equals S*=(k+p)
5.     Increment or Decrement Operators
     ++   increment
--    Decrement
Prefix operator à First adds one to the operand and stores the result to the variable on the left. Suffix operator à First assigns value to the variableon the left and the increments in the operand.
6.  Conditional Operator:-
A ternary operator “?:” is available in C to construct conditional expression s of the form
exp1? exp2:exp3;
7.    Bitwise operators:
&    Bitwise and
|     Bitwise or
^    Bitwise Ex-Or
<<  Shift Left
>>  Shift Right
~    Complement
8.    Special Operators:
C supports some special operators such as comma(,) ,size-of operator(Determines the length of  arrays and structures), pointer operator ( *) and member selection operators( . and -> )
Comma operators:-     Are used  to link the related expressions together .A comma linked list of expressions are evaluated left to right. The value of the rightmost expression is the value of the combined expression.
      Eg:- value=(x=10,y=5,x+y); 

No comments:

Post a Comment