SlideShare ist ein Scribd-Unternehmen logo
1 von 42
C Language
Operators
Engr. Qazi Shahzad Ali
C Language Operators
 Arithmetic Operators
 Increment Operator
 Decrement Operator
 Relational Operator
 Logical Operator
 Equality Operator
 Assignment Operator
 Conditional Operator
 Arithmetic expression
2
1-Arithmetic Operators
Operator Symbol Example
Multiplicatio
n
* a*b
Division / a/b
Addition + a+b
Subtraction - a-b
Modulus % a%b
3
Example for integers:
Exampl
e
Result
a*b 30
a/b 3
a+b 13
a-b 7
a%b 1
a=10
b=3
4
Example for floating point variable:
Exampl
e
Result
a*b 25.0
a/b 6.25
a+b 14.5
a-b 10.5
a%b NA
a=12.5
b=2.0
5
Example for Character:
Example Result
C1 80
c1+c2 164
c1+c2+5 169
c1+c2+
‘5’
217
Char C1,
C2
C1=‘T’
C2=‘P’
The ASCII code of ‘5’ is 53
6
2-Increment & Decrement Operators:
Operator Symbol Example
Increment ++ a++ or ++a
Decrement -- a-- or --a
7
2-Increment & Decrement Operators:
Operator Symbol Example
Increment ++ a++ or ++a
Decrement -- a-- or --a
8
3-Relational Operators
(use in decision making)
Operator
Symbo
l
Example
less than < a<b
greater than > a>b
less than or equal <= a<=b
greater than or
equal
>= a>=b
equal == a==b
Not equal != a!=b9
Example: i=1, j=2, k=3
Expression Meaning Value
i<j Correct 1
(i+j)>=k Correct 1
(j+k) > (i+5) wrong 0
K!=3 wrong 0
J==2 Correct 1
10
4-Logical Operator
Operator Symbol Example
AND && a<b && c>b
OR || a<b || c>b
NOT ! !(a<b)
11
Example: integer=i=7, float=f=5.5, character=c=‘w’
Expression Meaning Value
(i>=6)&&(c==‘w’) Correct 1
(i>6)||(c==119) Correct 1
(f<11)&&(i>100) wrong 0
(c!=‘p’)||(i+f)<=10 Correct 1
12
Operant Result
x y !x !y x&&y x||y
0 0 1 1 0 0
0
Non-
zero
1 0 0 1
Non-
zero
0 0 1 0 1
Non-
zero
Non-
zero
0 0 1 1
Logical Operators: AND, OR, NOT
13
Example: i=7, f=5.5
Expression Alternative expression Meanings
f>5 correct 1
!(f>5) wrong 0
i<=3 wrong 0
!(i<=3) correct 1
i>(f+1) correct 1
!(i>(f+1)) wrong 0
14
Bitwise Operator
Operator Symbol Example
AND & a&b
OR | (Pipe) a|b
Exclusive OR ^ (Caret) a^b
Complement ~ (Tilde) ~a
Right Shift >> a>>b
Left Shift << a<<b
15
Address and Indirection Operator:
Operator Symbol Example
Address & addr=&var
Indirection * Value=*addr
16
Memory Location:
3
i
6552
4
Location Name
Value at Location
Location Number
17
Conditional Operator
Generic Expression Example
result=(expression) ? Value1: value 2; max=(a>b) ? a:b;
If the expression is true (other than 0) then value 1 will be assigned to variable
“result”
If the expression is false (equal to 0) then value 2 will be assigned to variable “result”
18
Sizeof Operator:
Generic
Expression
Example
sizeof ()
sizeof(int), sizeof (struct
emp)
19
Algebraic Expression:
Algebraic Expression C Expression
a x b- c x d A *b-c*d
(m+n)(a+b) (m+n)*(a+b)
3x2+2x+5 3*x*x+2*x+5
a+b+c/d+e (a+b+c)/(d+e)
[2by/d+1-x/3(z+y)] 2*b*y/(d+1)-x/3*(z+y)
20
Assignment Operators
Operator Symbol Example
Equal(assign the value, different from
==)
= a=b
addition += a+=b (same as a=a+b)
subtraction -= a-=b (same as a=a-b)
multiplication *= a*=b (same as a=a*b)
division /= a/+b (same as a=a/b)
remainder %= a%=b (same as a=a%b)
Bitwise AND &= a&=b (same as a=a&b)
Bitwise inclusive OR |= a|=b (same as a=a|b)
Bitwise exclusive OR ^= a^=b (same as a=a^b)
Left shift <<= a<<=2 (same as a=<<2)
Right shift >>= a>>=3 (same as a=>>3)
21
Example: Assignment Operator
Expression Alternative expression
Variable 1+= variable 2 Variable 1=variable1 +variable 2
Variable 1-= variable 2 Variable 1=variable1 -variable 2
Meanings: The variable 1 on left side will add value
of variable 2 on right side and the resultant new value
will be assign to variable 1
22
Integer and Float Conversions:
24
Escape Sequence:
Escape sequence is used in the printf() function to do something to
the output.
Escape
Sequence
Effect
a Beep sound, alarm
b Backspace
f Form feed (for printing)
n New line
r Carriage return (move the curser to beginning of current line)
t Tab
v Vertical tab
 Backslash (to print  at output)
” Used to print (“) sign
’ Used to print (‘) sign
27
Format Specifier
Tells the printf() function the format of the output to be printed put
No Format Specifier Output Type Output Example
1 %d or %i Signed decimal integer (short) 76
2 %u Unsigned decimal integer (short) 76
3 %o Unsigned octal integer 134
4 %x Unsigned hexadecimal (small letter) 9c
5 %X Unsigned hexadecimal (capital letter) 9C
6 %f Integer including decimal point 76.0000
7 %e Signed floating point (using e notation) 7.6000e+01
8 %E Signed floating point (using E notation) 7.6000E+01
9 %g The shorter between %f and %e 76
10 %G The shorter between %f and %E 76
11 %c Single Character (both for signed & unsigned) ‘7’
12 %s String “76”
28
Filed–Width Specifiers:
With the help of this
Interpretation of a variable’s type
Width of the field
Number of decimal places printed
Justification
29
Example # 1: Field-Width Specifer:
A g e i s 3 3 .
A g e i s 3 3 .
A g e i s 3 3 .
printf(“Age is %2d.”, age);
printf(“Age is %4d.”, age);
printf(“Age is %6d.”, age);
30
Example # 2: Field-Width Specifer:
main()
{
Float temp=27.25;
printf(“The temperature is %f.”, temp);
}
Output:
The Temperature is 27.250000
main()
{
Float temp=27.25;
printf(“The temperature is %.2f.”, temp);
}
Output:
The Temperature is 27.25
31
Study the following example:
main()
{
printf(“%.1f%8.1f%8.1fn”,3.0,12.5,523.3);
printf(“%.1f%8.1f%8.1fn”,300.0,1200.5,52300.3);
}
What will be the output??
32
Output of Previous Example:
 output
3.0 12.5 523.3
300.0 1200.5 52300.3
In other way
3 . 0 1 2 . 5 5 2 3 . 3
3 0 0 . 0 1 2 0 0 . 5 5 2 3 0 0 . 3
8 8
8 8
33
Study the following example:
main()
{
printf(“%-.1f%-8.1f%-8.1fn”,3.0,12.5,523.3);
printf(“%-.1f%-8.1f%-8.1fn”,300.0,1200.5,52300.3);
}
What will be the output??
34
Output of Previous Example:
 output
In other way
3 . 0 1 2 . 5 5 2 3 . 3
3 0 0 . 0 1 2 0 0 . 5 5 2 3 0 0 . 3
8 8
8 8
300.0 1200.5 52300.3
3.0 12.5 523.3
35
Explanation:
%8.1f
%
8 . 1
f
Signals format
specification
field width
# of digits to the
right of decimal
Indicates
decimal-format
floating point
36
Scanf and Assignment:
scanf:
It is used to save the function input into its relavent
variable.
Assignment operator:
Its takes answer of a statement and saves into other
variable
37
Hierarchy of Operation:
Priority operator Description
1st * / %
multiplication, division ,
modular division
2nd + - addition , subtraction
3rd = Assignment
38
Associativity of operators
 When two expression contains two operators of
equal priority the tie between them is settled using
the associativity of the operators .
1. Left to right (left operand must be unambiguous)
2. Right to left (right operand must be unambiguous)
Means it must not be involved in evaluation of any
other sub-expression
Example:
a=3/2*5
39
Example: a=3/2*5
Operator left right remark
/ 3 2 or 2*5
Left operand
is
unambiguous
, Right is not
* 3/2 or 2 5
Right
operand is
unambiguous
, Left is not
Meanings: Since both have / and * have L to R associativity and
Only / has unambiguous, left operand (necessary condition for L to R associativity
is performed earlier.
40
Operator Associativity Chart
44
Evaluation:
kk=3/2*4+3/8+3
Solution:
 kk=3/2*4+3/8+3
 kk=1*4+3/8+3 operation : /
 kk=4+3/8+3 operation : *
 kk=4+0+3 operation : /
 kk=4+3 operation : +
 kk=7 operation : +
45
46
Solve the Question
i=2*3/4+4/4+8-2+5/8
Evaluation Exercise:
 i=2*3/4+4/4+8-2+5/8
Solution:
 i=2*3/4+4/4+8-2+5/8
 i=6/4+4/4+8-2+5/8 operation : *
 i=1+4/4+8-2+5/8 operation : /
 i=1+1+8-2+5/8 operation : /
 i=1+1+8-2+0 operation : /
 i=2+8-2+0 operation : +
 i=10-2+0 operation : +
 i=8+0 operation : -
 i=8 operation : +
47
48

Weitere ähnliche Inhalte

Was ist angesagt?

[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5sumitbardhan
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C Self employed
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)VC Infotech
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in CPrabhu Govind
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxNidhi Mehra
 

Was ist angesagt? (20)

[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Function in C
Function in CFunction in C
Function in C
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Operators
OperatorsOperators
Operators
 
C functions
C functionsC functions
C functions
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Static variables
Static variablesStatic variables
Static variables
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Report on c
Report on cReport on c
Report on c
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
 

Ähnlich wie Operators in C Programming

Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionalish sha
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptxramanathan2006
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdfMaryJacob24
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)SURBHI SAROHA
 
Operators-computer programming and utilzation
Operators-computer programming and utilzationOperators-computer programming and utilzation
Operators-computer programming and utilzationKaushal Patel
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxNithya K
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7REHAN IJAZ
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsAmrinder Sidhu
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
 

Ähnlich wie Operators in C Programming (20)

Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpression
 
Theory3
Theory3Theory3
Theory3
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
ICP - Lecture 5
ICP - Lecture 5ICP - Lecture 5
ICP - Lecture 5
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
Unit i intro-operators
Unit   i intro-operatorsUnit   i intro-operators
Unit i intro-operators
 
Operators-computer programming and utilzation
Operators-computer programming and utilzationOperators-computer programming and utilzation
Operators-computer programming and utilzation
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
 
Basics of c
Basics of cBasics of c
Basics of c
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 

Kürzlich hochgeladen

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfsmsksolar
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 

Kürzlich hochgeladen (20)

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 

Operators in C Programming

  • 2. C Language Operators  Arithmetic Operators  Increment Operator  Decrement Operator  Relational Operator  Logical Operator  Equality Operator  Assignment Operator  Conditional Operator  Arithmetic expression 2
  • 3. 1-Arithmetic Operators Operator Symbol Example Multiplicatio n * a*b Division / a/b Addition + a+b Subtraction - a-b Modulus % a%b 3
  • 4. Example for integers: Exampl e Result a*b 30 a/b 3 a+b 13 a-b 7 a%b 1 a=10 b=3 4
  • 5. Example for floating point variable: Exampl e Result a*b 25.0 a/b 6.25 a+b 14.5 a-b 10.5 a%b NA a=12.5 b=2.0 5
  • 6. Example for Character: Example Result C1 80 c1+c2 164 c1+c2+5 169 c1+c2+ ‘5’ 217 Char C1, C2 C1=‘T’ C2=‘P’ The ASCII code of ‘5’ is 53 6
  • 7. 2-Increment & Decrement Operators: Operator Symbol Example Increment ++ a++ or ++a Decrement -- a-- or --a 7
  • 8. 2-Increment & Decrement Operators: Operator Symbol Example Increment ++ a++ or ++a Decrement -- a-- or --a 8
  • 9. 3-Relational Operators (use in decision making) Operator Symbo l Example less than < a<b greater than > a>b less than or equal <= a<=b greater than or equal >= a>=b equal == a==b Not equal != a!=b9
  • 10. Example: i=1, j=2, k=3 Expression Meaning Value i<j Correct 1 (i+j)>=k Correct 1 (j+k) > (i+5) wrong 0 K!=3 wrong 0 J==2 Correct 1 10
  • 11. 4-Logical Operator Operator Symbol Example AND && a<b && c>b OR || a<b || c>b NOT ! !(a<b) 11
  • 12. Example: integer=i=7, float=f=5.5, character=c=‘w’ Expression Meaning Value (i>=6)&&(c==‘w’) Correct 1 (i>6)||(c==119) Correct 1 (f<11)&&(i>100) wrong 0 (c!=‘p’)||(i+f)<=10 Correct 1 12
  • 13. Operant Result x y !x !y x&&y x||y 0 0 1 1 0 0 0 Non- zero 1 0 0 1 Non- zero 0 0 1 0 1 Non- zero Non- zero 0 0 1 1 Logical Operators: AND, OR, NOT 13
  • 14. Example: i=7, f=5.5 Expression Alternative expression Meanings f>5 correct 1 !(f>5) wrong 0 i<=3 wrong 0 !(i<=3) correct 1 i>(f+1) correct 1 !(i>(f+1)) wrong 0 14
  • 15. Bitwise Operator Operator Symbol Example AND & a&b OR | (Pipe) a|b Exclusive OR ^ (Caret) a^b Complement ~ (Tilde) ~a Right Shift >> a>>b Left Shift << a<<b 15
  • 16. Address and Indirection Operator: Operator Symbol Example Address & addr=&var Indirection * Value=*addr 16
  • 17. Memory Location: 3 i 6552 4 Location Name Value at Location Location Number 17
  • 18. Conditional Operator Generic Expression Example result=(expression) ? Value1: value 2; max=(a>b) ? a:b; If the expression is true (other than 0) then value 1 will be assigned to variable “result” If the expression is false (equal to 0) then value 2 will be assigned to variable “result” 18
  • 20. Algebraic Expression: Algebraic Expression C Expression a x b- c x d A *b-c*d (m+n)(a+b) (m+n)*(a+b) 3x2+2x+5 3*x*x+2*x+5 a+b+c/d+e (a+b+c)/(d+e) [2by/d+1-x/3(z+y)] 2*b*y/(d+1)-x/3*(z+y) 20
  • 21. Assignment Operators Operator Symbol Example Equal(assign the value, different from ==) = a=b addition += a+=b (same as a=a+b) subtraction -= a-=b (same as a=a-b) multiplication *= a*=b (same as a=a*b) division /= a/+b (same as a=a/b) remainder %= a%=b (same as a=a%b) Bitwise AND &= a&=b (same as a=a&b) Bitwise inclusive OR |= a|=b (same as a=a|b) Bitwise exclusive OR ^= a^=b (same as a=a^b) Left shift <<= a<<=2 (same as a=<<2) Right shift >>= a>>=3 (same as a=>>3) 21
  • 22. Example: Assignment Operator Expression Alternative expression Variable 1+= variable 2 Variable 1=variable1 +variable 2 Variable 1-= variable 2 Variable 1=variable1 -variable 2 Meanings: The variable 1 on left side will add value of variable 2 on right side and the resultant new value will be assign to variable 1 22
  • 23. Integer and Float Conversions: 24
  • 24. Escape Sequence: Escape sequence is used in the printf() function to do something to the output. Escape Sequence Effect a Beep sound, alarm b Backspace f Form feed (for printing) n New line r Carriage return (move the curser to beginning of current line) t Tab v Vertical tab Backslash (to print at output) ” Used to print (“) sign ’ Used to print (‘) sign 27
  • 25. Format Specifier Tells the printf() function the format of the output to be printed put No Format Specifier Output Type Output Example 1 %d or %i Signed decimal integer (short) 76 2 %u Unsigned decimal integer (short) 76 3 %o Unsigned octal integer 134 4 %x Unsigned hexadecimal (small letter) 9c 5 %X Unsigned hexadecimal (capital letter) 9C 6 %f Integer including decimal point 76.0000 7 %e Signed floating point (using e notation) 7.6000e+01 8 %E Signed floating point (using E notation) 7.6000E+01 9 %g The shorter between %f and %e 76 10 %G The shorter between %f and %E 76 11 %c Single Character (both for signed & unsigned) ‘7’ 12 %s String “76” 28
  • 26. Filed–Width Specifiers: With the help of this Interpretation of a variable’s type Width of the field Number of decimal places printed Justification 29
  • 27. Example # 1: Field-Width Specifer: A g e i s 3 3 . A g e i s 3 3 . A g e i s 3 3 . printf(“Age is %2d.”, age); printf(“Age is %4d.”, age); printf(“Age is %6d.”, age); 30
  • 28. Example # 2: Field-Width Specifer: main() { Float temp=27.25; printf(“The temperature is %f.”, temp); } Output: The Temperature is 27.250000 main() { Float temp=27.25; printf(“The temperature is %.2f.”, temp); } Output: The Temperature is 27.25 31
  • 29. Study the following example: main() { printf(“%.1f%8.1f%8.1fn”,3.0,12.5,523.3); printf(“%.1f%8.1f%8.1fn”,300.0,1200.5,52300.3); } What will be the output?? 32
  • 30. Output of Previous Example:  output 3.0 12.5 523.3 300.0 1200.5 52300.3 In other way 3 . 0 1 2 . 5 5 2 3 . 3 3 0 0 . 0 1 2 0 0 . 5 5 2 3 0 0 . 3 8 8 8 8 33
  • 31. Study the following example: main() { printf(“%-.1f%-8.1f%-8.1fn”,3.0,12.5,523.3); printf(“%-.1f%-8.1f%-8.1fn”,300.0,1200.5,52300.3); } What will be the output?? 34
  • 32. Output of Previous Example:  output In other way 3 . 0 1 2 . 5 5 2 3 . 3 3 0 0 . 0 1 2 0 0 . 5 5 2 3 0 0 . 3 8 8 8 8 300.0 1200.5 52300.3 3.0 12.5 523.3 35
  • 33. Explanation: %8.1f % 8 . 1 f Signals format specification field width # of digits to the right of decimal Indicates decimal-format floating point 36
  • 34. Scanf and Assignment: scanf: It is used to save the function input into its relavent variable. Assignment operator: Its takes answer of a statement and saves into other variable 37
  • 35. Hierarchy of Operation: Priority operator Description 1st * / % multiplication, division , modular division 2nd + - addition , subtraction 3rd = Assignment 38
  • 36. Associativity of operators  When two expression contains two operators of equal priority the tie between them is settled using the associativity of the operators . 1. Left to right (left operand must be unambiguous) 2. Right to left (right operand must be unambiguous) Means it must not be involved in evaluation of any other sub-expression Example: a=3/2*5 39
  • 37. Example: a=3/2*5 Operator left right remark / 3 2 or 2*5 Left operand is unambiguous , Right is not * 3/2 or 2 5 Right operand is unambiguous , Left is not Meanings: Since both have / and * have L to R associativity and Only / has unambiguous, left operand (necessary condition for L to R associativity is performed earlier. 40
  • 39. Evaluation: kk=3/2*4+3/8+3 Solution:  kk=3/2*4+3/8+3  kk=1*4+3/8+3 operation : /  kk=4+3/8+3 operation : *  kk=4+0+3 operation : /  kk=4+3 operation : +  kk=7 operation : + 45
  • 41. Evaluation Exercise:  i=2*3/4+4/4+8-2+5/8 Solution:  i=2*3/4+4/4+8-2+5/8  i=6/4+4/4+8-2+5/8 operation : *  i=1+4/4+8-2+5/8 operation : /  i=1+1+8-2+5/8 operation : /  i=1+1+8-2+0 operation : /  i=2+8-2+0 operation : +  i=10-2+0 operation : +  i=8+0 operation : -  i=8 operation : + 47
  • 42. 48