SlideShare a Scribd company logo
1 of 35
C H A P T E R 5
O P E R A T O R S
PROG0101
FUNDAMENTALS OF
PROGRAMMING
CHAPTER 4
VARIABLES AND DATA
TYPES
PROG0101
FUNDAMENTALS OF PROGRAMMING
CHAPTER 3
ALGORITHMS
PROG0101
FUNDAMENTALS OF PROGRAMMING
C H A P T E R 1
O V E R V I E W O F C O M P U T E R S A N D L O G I C
PROG0101
FUNDAMENTALS OF
PROGRAMMING
PROG0101
FUNDAMENTALS OF PROGRAMMING
CHAPTER 5
OPERATORS
2
Operators
 An operator is a symbol, which helps the user to command
the computer to do a certain mathematical or logical
manipulations.
 Operators are used in programming language program to
operate on data and variables.
3
Operators
 Types of Operators:
 Arithmetic operators
 Relational Operators
 Logical Operators
 Increments and Decrement Operators
4
Arithmetic Operators
Arithmetic Operators
 You can use an arithmetic operator with one or two
arguments to add, subtract, multiply, and divide numeric
values.
Operator Name Description
+ Addition to add two numbers together
- Subtraction to subtract one number from another
* Multiplication to multiply one number by another.
/ Division to divide one number by another.
% Modulus (Remainder) to find the remainder from dividing
one number by another.
5
Arithmetic Operators
Examples:
i. 5 + 3 = 8
ii. 5 – 3 = 2
iii. 5 * 3 = 15
iv. 5 / 3 = 1
v. 5 % 3 = 2
6
Arithmetic Operators
 *, / and % will be performed before + or - in any expression.
 Brackets can be used to force a different order of evaluation
to this.
7
Arithmetic Operators
Example
i. 2 + 5 * 4 – 3 = ?
ii. (2 + 5) * (4 – 3) = ?
8
Arithmetic Operators
 Here are some arithmetic expressions used within
assignment statements:
i. z = x + y
ii. no1 = x – y
iii. age = a * b + c
iv. velocity = distance / time
v. force = mass * acceleration
vi. count = count + 1
9
Integer Arithmetic
Integer Arithmetic
 When an arithmetic operation is performed on two whole
numbers or integers than such an operation is called as
integer arithmetic.
 It always gives an integer as the result.
10
Integer Arithmetic
Example
Let x = 27 and y = 5 be two integer numbers. Then the integer
operation leads to the following results:
i. x + y = 32
ii. x – y = 22
iii. x * y = 115
iv. x % y = 2
v. x / y = 5
11
Floating-point Arithmetic
Floating-point Arithmetic
 When an arithmetic operation is preformed on two real
numbers or fraction numbers such an operation is called
floating-point arithmetic.
12
Floating-point Arithmetic
Example
Let x = 14.0 and y = 4.0 then
i. x + y = 18.0
ii. x – y = 10.0
iii. x * y = 56.0
iv. x / y = 3.50
13
Relational Operators
 An operator that compares two values.
 For example, the expression:
 This expression will have a value of TRUE if the variable x
is less than 5; otherwise the value of the expression will be
FALSE.
x < 5
means x is less than 5
14
Relational Operators
 Relational operators are sometimes called comparison
operators.
 Expressions that contain relational operators are called
relational expressions.
 A simple relational expression contains only one relational
operator and takes the following form:
 Where exp1 and exp2 are expressions, which may be simple
constants, variables or combination of them.
<exp1> relational operator <exp2>
15
Relational Operators
 The following are relational operators:
Operator Name Description
< Less than
Indicates whether the value of the left
operand is less than the value of the
right operand.
<= Less than or equal to
Indicates whether the value of the left
operand is less than or equal to the value
of the right operand.
> Greater than
Indicates whether the value of the left
operand is greater than the value of the
right operand.
>=
Greater than or equal
to
Indicates whether the value of the left
operand is greater than or equal to the
value of the right operand.
16
Relational Operators
 The following are relational operators:
Operator Name Description
== Equal to
Indicates whether the value of the left
operand is equal to the value of the right
operand.
!= Not equal to
Indicates whether the value of the left
operand is not equal to the value of the
right operand.
17
Relational Operators
Example:
Let x = 2 and y = 5 then
i. x < y = True
ii. (x + 2) > (y * 2) = False
iii. (x + 3) <= y = True
iv. x != y = True
v. y > (3 + x) = False
18
Logical Operators
 An operator that compare or evaluate logical and relational
expressions.
 The following are logical operators:
Operator Name
&& Logical AND
|| Logical OR
! Logical NOT
19
Logical Operators
Logical AND
 This operator is used to evaluate two conditions or
expressions with relational operators simultaneously.
 If both the expressions to the left and to the right of the
logical operator is true then the whole compound
expression is true.
Exp1 Exp2 Exp1 && Exp2
False False False
True False False
False True False
True True True
20
Logical Operators
Logical AND
Example:
(a > b) && (x == 10)
The expression to the left is a > b and that on the right is x ==
10, the whole expression is true only if both expressions are
true i.e., if a is greater than b and x is equal to 10.
21
Logical Operators
Logical AND
Example:
Given a = 2, b = 3 and c = 5, evaluate the following logical
expressions:
i. (a > b) && (c != 5) = False
ii. (a < b) && (c < b) = False
iii. (a > b) && (c == 5) = False
iv. (a < b) && (b < c) = True
22
Logical Operators
Logical OR
 The logical OR is used to combine two expressions or the
condition evaluates to true if any one of the 2 expressions is true.
 The expression evaluates to true if any one of them is true or if
both of them are true.
Exp1 Exp2 Exp1 || Exp2
False False False
True False True
False True True
True True True
23
Logical Operators
Logical OR
Example:
(a < m) || (a < n)
The expression evaluates to true if any one of them is true or
if both of them are true.
24
Logical Operators
Logical OR
Example:
Given a = 2, b = 3 and c = 5, evaluate the following logical
expressions:
i. (a > b) || (c != 5) = False
ii. (a < b) || (c < b) = True
iii. (a > b) || (c == 5) = True
iv. (a < b) || (b < c) = True
25
Logical Operators
Logical NOT
 The logical NOT operator takes single expression and
evaluates to true if the expression is false and evaluates to
false if the expression is true.
 In other words it just reverses the value of the expression.
Exp1 !Exp1
True False
False True
26
Logical Operators
Logical NOT
Example:
! (x >= y)
The NOT expression evaluates to true only if the value of x is
neither greater than or equal to y
27
Logical Operators
Logical NOT
Example:
Given a = 2, b = 3 and c = 5, evaluate the following logical
expressions:
a) !(a > b) = True
b) !(a < b) = False
c) !(a > b || c == 5) = False
28
Increment and Decrement Operators
 The increment and decrement operators are one of the
unary operators which are very useful in programming
language.
 They are extensively used in loops.
 The syntax of the operators is given below:
++ variable name
variable name++
– –variable name
variable name– –
29
Increment and Decrement Operators
 The increment operator ++ adds the value 1 to the current
value of operand.
 The decrement operator – – subtracts the value 1 from the
current value of operand.
30
Increment and Decrement Operators
Example:
Consider the following:
m = 5;
y = ++m; (prefix)
In this case the value of y and
m would be 6.
Suppose if we rewrite the above
statement as
m = 5;
y = m++; (postfix)
Then the value of y will be 5 and
that of m will be 6.
31
Increment and Decrement Operators
 A prefix operator first adds 1 to the operand and then the
result is assigned to the variable on the left.
 On the other hand, a postfix operator first assigns the
value to the variable on the left and then increments the
operand.
32
Increment and Decrement Operators
Example 1:
x = 4
y = ++x
PRINT x
PRINT y
What is the output?
5
5
33
Increment and Decrement Operators
Example 2:
x = 3
y = x++
PRINT x
PRINT y
What is the output?
4
3
34
Increment and Decrement Operators
Example 3:
x = 3
y = --x
PRINT x
PRINT y
What is the output?
2
2
35
Increment and Decrement Operators
Example 4:
x = 3
y = x--
PRINT x
PRINT y
What is the output?
2
3

More Related Content

What's hot

Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Deepak Singh
 
Operators
OperatorsOperators
OperatorsKamran
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions NotesProf Ansari
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of PrecedenceMuhammad Hammad Waseem
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming Kamal Acharya
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 

What's hot (18)

Python Operators
Python OperatorsPython Operators
Python Operators
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Python : basic operators
Python : basic operatorsPython : basic operators
Python : basic operators
 
Operators
OperatorsOperators
Operators
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
Session03 operators
Session03 operatorsSession03 operators
Session03 operators
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 

Similar to Fundamentals of Programming Chapter 5

Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)jahanullah
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxranaashutosh531pvt
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptxrinkugupta37
 
Project in TLE
Project in TLEProject in TLE
Project in TLEPGT_13
 
Programming presentation
Programming presentationProgramming presentation
Programming presentationFiaz Khokhar
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and VariablesGenard Briane Ancero
 
Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Genard Briane Ancero
 
Cse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionCse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionFarshidKhan
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingRahul Tandale
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptxclassall
 

Similar to Fundamentals of Programming Chapter 5 (20)

Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
Project in TLE
Project in TLEProject in TLE
Project in TLE
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and Variables
 
Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)
 
Cse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionCse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expression
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptx
 
Operators
OperatorsOperators
Operators
 
C Operators
C OperatorsC Operators
C Operators
 
Opreator In "C"
Opreator In "C"Opreator In "C"
Opreator In "C"
 

More from Mohd Harris Ahmad Jaal

Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Mohd Harris Ahmad Jaal
 

More from Mohd Harris Ahmad Jaal (20)

Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
 
Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
 
Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
 
Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1Web Application Development using PHP Chapter 1
Web Application Development using PHP Chapter 1
 
Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10
 
Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9
 
Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8
 
Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7
 
Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6
 
Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Fundamentals of Programming Chapter 5

  • 1. C H A P T E R 5 O P E R A T O R S PROG0101 FUNDAMENTALS OF PROGRAMMING CHAPTER 4 VARIABLES AND DATA TYPES PROG0101 FUNDAMENTALS OF PROGRAMMING CHAPTER 3 ALGORITHMS PROG0101 FUNDAMENTALS OF PROGRAMMING C H A P T E R 1 O V E R V I E W O F C O M P U T E R S A N D L O G I C PROG0101 FUNDAMENTALS OF PROGRAMMING PROG0101 FUNDAMENTALS OF PROGRAMMING CHAPTER 5 OPERATORS
  • 2. 2 Operators  An operator is a symbol, which helps the user to command the computer to do a certain mathematical or logical manipulations.  Operators are used in programming language program to operate on data and variables.
  • 3. 3 Operators  Types of Operators:  Arithmetic operators  Relational Operators  Logical Operators  Increments and Decrement Operators
  • 4. 4 Arithmetic Operators Arithmetic Operators  You can use an arithmetic operator with one or two arguments to add, subtract, multiply, and divide numeric values. Operator Name Description + Addition to add two numbers together - Subtraction to subtract one number from another * Multiplication to multiply one number by another. / Division to divide one number by another. % Modulus (Remainder) to find the remainder from dividing one number by another.
  • 5. 5 Arithmetic Operators Examples: i. 5 + 3 = 8 ii. 5 – 3 = 2 iii. 5 * 3 = 15 iv. 5 / 3 = 1 v. 5 % 3 = 2
  • 6. 6 Arithmetic Operators  *, / and % will be performed before + or - in any expression.  Brackets can be used to force a different order of evaluation to this.
  • 7. 7 Arithmetic Operators Example i. 2 + 5 * 4 – 3 = ? ii. (2 + 5) * (4 – 3) = ?
  • 8. 8 Arithmetic Operators  Here are some arithmetic expressions used within assignment statements: i. z = x + y ii. no1 = x – y iii. age = a * b + c iv. velocity = distance / time v. force = mass * acceleration vi. count = count + 1
  • 9. 9 Integer Arithmetic Integer Arithmetic  When an arithmetic operation is performed on two whole numbers or integers than such an operation is called as integer arithmetic.  It always gives an integer as the result.
  • 10. 10 Integer Arithmetic Example Let x = 27 and y = 5 be two integer numbers. Then the integer operation leads to the following results: i. x + y = 32 ii. x – y = 22 iii. x * y = 115 iv. x % y = 2 v. x / y = 5
  • 11. 11 Floating-point Arithmetic Floating-point Arithmetic  When an arithmetic operation is preformed on two real numbers or fraction numbers such an operation is called floating-point arithmetic.
  • 12. 12 Floating-point Arithmetic Example Let x = 14.0 and y = 4.0 then i. x + y = 18.0 ii. x – y = 10.0 iii. x * y = 56.0 iv. x / y = 3.50
  • 13. 13 Relational Operators  An operator that compares two values.  For example, the expression:  This expression will have a value of TRUE if the variable x is less than 5; otherwise the value of the expression will be FALSE. x < 5 means x is less than 5
  • 14. 14 Relational Operators  Relational operators are sometimes called comparison operators.  Expressions that contain relational operators are called relational expressions.  A simple relational expression contains only one relational operator and takes the following form:  Where exp1 and exp2 are expressions, which may be simple constants, variables or combination of them. <exp1> relational operator <exp2>
  • 15. 15 Relational Operators  The following are relational operators: Operator Name Description < Less than Indicates whether the value of the left operand is less than the value of the right operand. <= Less than or equal to Indicates whether the value of the left operand is less than or equal to the value of the right operand. > Greater than Indicates whether the value of the left operand is greater than the value of the right operand. >= Greater than or equal to Indicates whether the value of the left operand is greater than or equal to the value of the right operand.
  • 16. 16 Relational Operators  The following are relational operators: Operator Name Description == Equal to Indicates whether the value of the left operand is equal to the value of the right operand. != Not equal to Indicates whether the value of the left operand is not equal to the value of the right operand.
  • 17. 17 Relational Operators Example: Let x = 2 and y = 5 then i. x < y = True ii. (x + 2) > (y * 2) = False iii. (x + 3) <= y = True iv. x != y = True v. y > (3 + x) = False
  • 18. 18 Logical Operators  An operator that compare or evaluate logical and relational expressions.  The following are logical operators: Operator Name && Logical AND || Logical OR ! Logical NOT
  • 19. 19 Logical Operators Logical AND  This operator is used to evaluate two conditions or expressions with relational operators simultaneously.  If both the expressions to the left and to the right of the logical operator is true then the whole compound expression is true. Exp1 Exp2 Exp1 && Exp2 False False False True False False False True False True True True
  • 20. 20 Logical Operators Logical AND Example: (a > b) && (x == 10) The expression to the left is a > b and that on the right is x == 10, the whole expression is true only if both expressions are true i.e., if a is greater than b and x is equal to 10.
  • 21. 21 Logical Operators Logical AND Example: Given a = 2, b = 3 and c = 5, evaluate the following logical expressions: i. (a > b) && (c != 5) = False ii. (a < b) && (c < b) = False iii. (a > b) && (c == 5) = False iv. (a < b) && (b < c) = True
  • 22. 22 Logical Operators Logical OR  The logical OR is used to combine two expressions or the condition evaluates to true if any one of the 2 expressions is true.  The expression evaluates to true if any one of them is true or if both of them are true. Exp1 Exp2 Exp1 || Exp2 False False False True False True False True True True True True
  • 23. 23 Logical Operators Logical OR Example: (a < m) || (a < n) The expression evaluates to true if any one of them is true or if both of them are true.
  • 24. 24 Logical Operators Logical OR Example: Given a = 2, b = 3 and c = 5, evaluate the following logical expressions: i. (a > b) || (c != 5) = False ii. (a < b) || (c < b) = True iii. (a > b) || (c == 5) = True iv. (a < b) || (b < c) = True
  • 25. 25 Logical Operators Logical NOT  The logical NOT operator takes single expression and evaluates to true if the expression is false and evaluates to false if the expression is true.  In other words it just reverses the value of the expression. Exp1 !Exp1 True False False True
  • 26. 26 Logical Operators Logical NOT Example: ! (x >= y) The NOT expression evaluates to true only if the value of x is neither greater than or equal to y
  • 27. 27 Logical Operators Logical NOT Example: Given a = 2, b = 3 and c = 5, evaluate the following logical expressions: a) !(a > b) = True b) !(a < b) = False c) !(a > b || c == 5) = False
  • 28. 28 Increment and Decrement Operators  The increment and decrement operators are one of the unary operators which are very useful in programming language.  They are extensively used in loops.  The syntax of the operators is given below: ++ variable name variable name++ – –variable name variable name– –
  • 29. 29 Increment and Decrement Operators  The increment operator ++ adds the value 1 to the current value of operand.  The decrement operator – – subtracts the value 1 from the current value of operand.
  • 30. 30 Increment and Decrement Operators Example: Consider the following: m = 5; y = ++m; (prefix) In this case the value of y and m would be 6. Suppose if we rewrite the above statement as m = 5; y = m++; (postfix) Then the value of y will be 5 and that of m will be 6.
  • 31. 31 Increment and Decrement Operators  A prefix operator first adds 1 to the operand and then the result is assigned to the variable on the left.  On the other hand, a postfix operator first assigns the value to the variable on the left and then increments the operand.
  • 32. 32 Increment and Decrement Operators Example 1: x = 4 y = ++x PRINT x PRINT y What is the output? 5 5
  • 33. 33 Increment and Decrement Operators Example 2: x = 3 y = x++ PRINT x PRINT y What is the output? 4 3
  • 34. 34 Increment and Decrement Operators Example 3: x = 3 y = --x PRINT x PRINT y What is the output? 2 2
  • 35. 35 Increment and Decrement Operators Example 4: x = 3 y = x-- PRINT x PRINT y What is the output? 2 3