Vous êtes sur la page 1sur 14

w 

c An operator is a symbol that is used to manipulate the


data. The data items that the operator acts upon are
called operands.
c The operator that acts upon single operand is
called unary operator and the operator that acts upon
two operands is called binary operator and the
operator that acts upon three operands is called
ternary operator.
9 

c Arithmetic operators
c Relational Operators
c Logical Operators
c Assignment Operators
c Increments and Decrement Operators
c Conditional Operator
c Bitwise Operators
c Special Operators
%
w 

c There are five arithmetic operators in C. the arithmetic


operators are binary operators. The following table
gives the arithmetic operators and their meaning.
c Let a=10 and b=5

w          

+ Addi
i  +  +3 9
- Sub
 
i    -b 5
* Mul
ili
i  *  *  
 ivii   ub  5
Mdul divii iv

%  % b%
 i d     

Π   


 
       
   
 
 

c Relational operators are used to test or compare two


numeric or character expressions.
c There are six relational operators in C and they
require two operands.
c The relational operators when applied produce an
integer value 0 (False) or 1(True), and are referred to as
logical values.
c The following table gives the relational operators and
their meaning.
c Let a=10 and b=5
The expressions formed with the help of relational operators are
called relational expression. The result of relational expression is
either 1 (true) or 0 (False).

w          

º 

  º ºb
º 

  u l  º º  9u
!
   b  " l
 !
  u l
   b  9u
 #u l
   b  " l
$ %
u l
  $ &$b 9u
¬ 
w 

c Logical operators are used to compare relational


expressions.
c The expressions involving logical operators are called
compound expression since they at least need two
relational expressions
c There are three logical operators.
c Op1 and op2 are result of relational expression.
w      
-- AN  -- 
''   '' 
$ N
$
c The following is the table for && and ||

c Truth table for !


w  w  w 

w  w 

w 

   
 
 

w  w 


c × 
c Let a=10, b=15 and c=5
    
 () **  ( " l 
 () ''  ( 
ue
$ () 9ue
%   
 

c Assignment operators are used to assign value to a variable. The


expression to the right of the operator is evaluated and the result is
assigned to the variable on the left.
c   
c × 
c Let a=10
c X=a+5 then the result in X=15
 

 
%   
  

c The arithmetic operators can be combined with the


assignment operator to get shorthand assignment
operators. Use of shorthand assignment operator
reduces the length of the expression.
c Let a=10 and b=5. The following table explains the
shorthand assignment operators.
w          

+  +   + +5 5


-  -   - b- 3
*  *   * *b 45
       5 9
%  %   % b%
à  
 
  

 
c The increment (++) and decrement (--) are unary operators.
c The operand must be a variable and cannot be constant or
expression.
c The ++ operator increments the operand by one and the
decrement operator decrements the operators by 1.
c The increment and decrement operator can precede or succeed
the operand.
c If the operator precedes the operand then operand is
incremented or decremented before it is used.
c If the operator succeeds the operand then the operand is
incremented or decremented after it is used.
c × 
c A++ i-- ++d --dif
ñ  
 
c Conditional operator is a ternary operator.
c It is used to build simple conditional expressions.

c   
c The expression1 is evaluated first. If it is true the expression 2 is evaluated and value is
assigned to the variable and if the condition is false then expression3 is evaluated and the value is
assigned to the variable.
c Expression 1 is a relational or logical expression
c Expression 2 can be arithmetic, relational or logical expression.
c × 
c Big=a>b ? a : b
c In this example if the expression a>b is true then big is assigned the value of a else the value
of b is assigned to the big

å  ·  


 
 
 

Vous aimerez peut-être aussi