You are on page 1of 17

BY : BHAVPRITA

ROLL NO: 09
 An operator is a symbol that tells the compiler to
perform certain ,mathematical and logical
operations

 Operators are used in program to manipulate data


and variables
 In C operators are classified into number of
categories :
 1. Assignment operators
 2. Increment / Decrement operators
 3. Arithmetic operators
 4. Relational operators
 5. Logical operators
 6. Conditional operators
 7. Special operators
 An assignment operator is used to assign the
constant value or a value of one variable to another

 = is an assignment operator

 It has R to L (right to left) associativity

 It is useful when assigning the same value in a


number of variables as follows :

 A=B=C=10 ;
 These operators are specially used for incrementing
/decrementing the value of the variable by 1 only

 Increment operator : ++

 Decrement operator : --
 Increment and Decrement operators are of two types
:
++ / --

Pre increment /decrement Post increment /decrement


( ++a , --a) (a++ , a--)
 1. Pre-increment /decrement rule :
 Change the value then evaluate
 Example :
 int x = 4 ; ++x ; x = 5 ;
 int y = 4 ; --y ; y = 3 ;

 2. Post-increment / decrement rule :


 Evaluate and then change the value
 Example :
 int x = 4 ; x++ ; x = 4 ; x = 5 ;
 int y = 4 ; y-- ; y = 4 ; y = 3 ;
 Arithmetic operators are used to perform
arithmetic operations
 These operator acts upon two operands
 There are following arithmetic operators in C :
 Relational operators are the symbols that are
used to compare two values and the
comparison is always in terms of True or
False , i.e ; 0 / 1

 It has lower precedence than than the


arithmetic operator

 The associativity of relational operator is L


to R
 Logical operators are used to combine two or
more conditions into one condition

 The output of the given conditions are always


logical ,i.e. ; either true or false (0 or 1)
 The conditional operator is also called as
ternary operator because it works with three
operands

 This operator is used for decision making

 Syntax : Condition ? TRUE Part : FALSE Part ;


 Example :
a % 2 ==0 ? Even : Odd ;
In this , first we check the
condition then only one
part will be come as an
output according to the
condition. If the condition is
true the true part will be
shown otherwise the false
part will performed
 In C there are following special operators :

 1. sizeof :

 This operator is used to find the size of the memory (in bytes) allocated
for a variable

 Syntax : sizeof(variable_name);

 2. pointer (*) :

 This operator is used to define pointer variables

 3. Dot operator (.) :

 This operator is used to access members of structure or union.

You might also like