SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente (20)

Control statements
Control statementsControl statements
Control statements
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
C++
C++C++
C++
 
Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
C presentation book
C presentation bookC presentation book
C presentation book
 
C tutorial
C tutorialC tutorial
C tutorial
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 
Loops in c
Loops in cLoops in c
Loops in c
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 

Similar a 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
 

Similar a 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
 

Último

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
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
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfrs7054576148
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 

Último (20)

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
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
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
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
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 

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