0% found this document useful (0 votes)
15 views

Pps u1 Lesson Operators in c Part-1 (1)

Uploaded by

Akhilesh Koganti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Pps u1 Lesson Operators in c Part-1 (1)

Uploaded by

Akhilesh Koganti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

OPERATOR

S IN C
Operator :
An operator is a symbol that tells the computer to perform certain
mathematical or logical manipulations. Operators are used in programs to
manipulate data and variables.
Example : +,-,> etc.

Operation :
The process of computation that happens in an expression based on
operator.
Example : Addition, subtraction, greater than etc.

Operand :
The data items involved in an operation or the data on which operands act
to produce result is known as operand.
Example : Addition, subtraction, greater than etc.
FIG : ILLUSTRATTION OF OPERATOR,OPERAND,OPERATION

OPERATION

ADDITION
c = a + b;

OPERANDS OPERATOR
TYPES OF OPERATORS

Based on numbers of operands an operator act upon


There are 3 types of operators in C.

UNARY OPERATOR -> ACTS ON 1 OPERAND

BINARY OPERATOR -> ACTS ON 2 OPERANDS

TERNARY OPERATOR -> ACTS ON 3 OPERANDS

C language supports a rich set of built-in operators.


TYPES OF OPERATORS
C operators can be classified into a number of categories
based on the type of operation they perform, they are

1.Arithmetic Operators
2.Relational Operators
3.Logical Operators
4.Assignment Operators
5.Increment and Decrement operators
6.Conditional operators
7.Bitwise Operators
8.Special operators
1.Arithmetic Operators
 C provides all the 5 basic arithmetic operators.
 An arithmetic operator performs mathematical operations such as addition,
subtraction, multiplication, division etc on numerical values.

Operator Meaning Examples

+ Addition c=a+5;a=b+c;h=9+6;

- Subtraction d=e-f;

* Multiplication k=3*g;

/ Division (quotient) m=u/v;

% Modulo division (remainder) I=j%k


Integer Arithmetic:
If both the operands in an arithmetic expression are integers then it is
known as integer arithmetic and the result is an integer.

int  int AOP int

Real Arithmetic:
If both the operands in an arithmetic expression are real operands then it
is known as real arithmetic and the result is real.

float  float AOP float (or) double  double AOP double

Mixed mode Arithmetic:


If the operands in an arithmetic expression are of different types then it is
known as mixed mode arithmetic and the result is a bigger type.

float  float AOP int (or) float  int AOP float


2. Relational Operators
 Relational operators are used for comparing two quantities, and used for decision
making.
 An expression containing a relational operator is termed as a relational expression.
 The value of a relational expression is either one or zero.
 It is one if the specified relation is true and zero if the relation is false.

Operator Meaning Example Result


< is less than a<6 (a=7) 0
<= is less than or equal to x<=y (x=4,y=7) 1
> is greater than t 9>8 1
>= is greater than or equal x+10 >=y (x=4,y=7) 1
to
== is equal to 8==8 1
!= is not equal to 6!=5 1
3. Logical OperatorS
 C supports 3 logical operators.
 The logical operators are used when we want to test more than one condition and
make decisions.
 Logical operators return 0 or 1.
 The operators are as LOGICAL AND,LOGICAL OR,LOGICAL NOT

Operator Meaning Example Result

&& Logical AND 4>3 && 5!=6 1

|| Logical OR 5<=7 || 5==5 1

! Logical NOT !(5==4) 1


The truth table for Logical AND and Logical OR is as below

OP1 OP2 OP1&&OP2 OP1||OP2


0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1

Logical Not :
 It is TRUE if the Expression evaluates to FALSE

 It is FALSE if the Expression evaluates to TRUE

 Both LOGICAL AND , LOGICAL OR are BINARY operators

 LOGICAL NOT is an UNARY operator


4.Assignment operatorS
 These operators are used to assign the result of an expression to a variable.
 They are also available as Short Hand Assignment Operators.
 They are applied with Arithmetic and Bitwise Operators

Operator Meaning Example


= Assignment a=5; x=y; r=s*t;
+= Sum equal to b+=5 implies b=b+5
-= Subtract and assign c-=55 implies c=c-55
*= Multiply equal to b*=5 implies b=b*5
/= Divide equal to a/=10 implies a=a/10
%= Remainder equal to d%=7 implies d=d%7
5. Increment and Decrement
operators
 ++ and - - are increment and decrement operators in C.
 The operator ++ adds 1 to the operand, while - - subtracts 1 from the operand.
 Both are UNARY operators.
 They exist in postfix and prefix forms.
 They act only on variables. (int)

Operator Form Meaning Examples


++ a++ Post increment i++
++a Pre increment ++sum
-- b-- Post decrement j--
--b Pre decrement --count
6. Conditional operator

A ternary operator is a “? :” pair which is available in C to


construct conditional expressions of the form

exp1 ? exp2 : exp3

where exp1,exp2 and exp3 are expressions.


Here exp 1 is expected to be a condition that evaluates to true or
false.
This is a Ternary Operator in C.

Example :

maxNum = (num1 > num2) ? num1 : num2;


FIG : ILLUSTRATION OF TERANARY
OPERATOR

Val = Exp2 if Exp1 is TRUE otherwise


Val = Exp3 if Exp1 is FALSE

Val = Exp1 ? Exp 2 : Exp 3;


f t
a r
Exp1 =TRUE => Val = Exp2
l u
s e
e Exp1 =FALSE => Val = Exp3
7. Bitwise Operators:
C supports a special operator knows as bitwise operators for manipulation of data
at bit level.
These operators are used for testing the bits, or shifting them right to left.
Note: Bitwise operators may not be applied to float or double.
Except Bitwise ones complement which is UNARY rest all Bitwise operators are
BINARY.

Operator Meaning Example


& Bitwise AND X&y
| Bitwise OR x|y
^ Bitwise exclusive OR X^y
<< Shift left X<<y
>> Shift right X>>y
~ Bitwise ones complement ~y
TRUTH TABLE OF BITIWSE OPERATORS
8.Special Operators
 C supports some special operators such as comma operator, size of operator,
pointer operators(& and *) and member selection operators (. and -> ).
THANK YOU

You might also like