0% found this document useful (0 votes)
4 views18 pages

Session 5 - Prog Pract Tech

The document outlines the objectives and definitions of operators in programming, categorizing them into arithmetic, relational, and logical types. It explains the use of these operators, their precedence, and how they can be combined in expressions, including the use of parentheses to override precedence rules. The document also includes tables detailing various operators and their functions, along with examples.

Uploaded by

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

Session 5 - Prog Pract Tech

The document outlines the objectives and definitions of operators in programming, categorizing them into arithmetic, relational, and logical types. It explains the use of these operators, their precedence, and how they can be combined in expressions, including the use of parentheses to override precedence rules. The document also includes tables detailing various operators and their functions, along with examples.

Uploaded by

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

Fo

rA
pt
ec
h

Operators
C
en
tre
U
se
O
nl
y
Objectives

y
nl
O
Define operators

se
List the different types of operators

U
Describe the use of arithmetical operators

tre
Describe the use of relational operators to

en
make comparisons
C
Explain the process of associating selections
h
ec

with logical operators


pt

Identify the precedence of operators in an


rA

expression
Fo
Introduction

y
nl
O
Computer operations can

se
be arithmetic such as

U
addition, division, or even

tre
comparison where one

en
variable is compared to
another variable.
C
h
ec

These kinds of operations


pt

are performed using


rA

operators.
Fo
Operators

y
nl
O
Operators:

se
A set of symbols that help to manipulate or

U
perform some sort of function on data

tre
en
The three types of operators are as follows:
C
h
Arithmetic Operators
ec

Relational Operators
pt

Logical Operators
rA
Fo
Using Arithmetic Operators 1-3

y
nl
O
Arithmetic operators:

se
Help to manipulate numeric data

U
Help perform common arithmetic operation on

tre
the data

en
C
h
ec
pt
rA
Fo
Using Arithmetic Operators 2-3

y
nl
O
The table shows a list of arithmetic operators

se
common to most programming languages.

U
Operator Description Example Result C Equivalent

tre
+ Addition 9+2 11 +

en
- Subtraction 9–2 7 -
/ Division
C 9/2 4.5 /
h
* Multiplication 9*2 18 *
ec

^ Exponentiatio 9^2 81 ^
pt

n
rA

MOD Modulus 9 MOD 2 1 %


- Negation -9 -9 -
Fo
Using Arithmetic Operators 3-3

y
nl
O
The negation operator

se
Requires only a single operand

U
Is also known as a unary operator

tre
en
All other operators require two operands and
h
C
are known as binary operators.
ec
pt
rA
Fo
Precedence between Arithmetic
Operators

y
nl
O
The table shows the order in which each arithmetic

se
operator precedes over other arithmetic operators.

U
tre
Precedence Operator Description

en
1 ++ Increment
2
3 C--
*, /, MOD
Decrement
Multiplication, Division,
h
ec

Modulus
4 +, - Addition, Subtraction
pt
rA
Fo
Using Relational Operators 1-2

y
nl
O
Relational operators:

se
Compare two or more values or expressions and

U
always return either ‘True’ or ‘False’

tre
Are binary operators

en
C
h
ec
pt
rA
Fo
Using Relational Operators 2-2

y
nl
O
The table shows a list of relational operators

se
common to most languages.

U
tre
Operator Description Example Result C Equivalent

en
< Less than 2<9 True <
<= Less than or Equal 2<=9 True <=
to C
h
> Greater than 2>9 False >
ec

>= Greater than or 2>=9 False >=


pt

Equal to
rA

= Equal to 2=9 False ==


Fo

<> Not Equal to 2<>9 True <>


Precedence between Relational Operators

y
nl
O
There is no precedence among relational

se
operators.

U
tre
Therefore, they are always evaluated from left

en
to right.
C
h
ec
pt
rA
Fo
Using Logical Operators 1-2

y
nl
O
Logical operators:

se
Are used in situations where multiple conditions

U
need to be satisfied

tre
Combine the results of several comparisons, as

en
required, to present a single answer
C
Return the results in either ‘True’ or ‘False’
h
ec
pt

Age > 18 AND City = ‘New York’


rA
Fo
Using Logical Operators 2-2

y
nl
O
The table shows a list of logical operators.

se
U
Operator Description C Equivalent

tre
AND Result is ‘True’ only when both &&
conditions are ‘True’

en
OR Result is ‘True’ when either of the ||

C
two conditions is ‘True’
h
NOT Operates on a single value and !
ec

converts ‘True’ to ‘False’ and vice-


versa
pt
rA
Fo
Precedence between Logical Operators

y
nl
O
The table shows the precedence order for

se
logical operators.

U
tre
Precedence Operator
1 NOT

en
2 AND
3
C OR
h
ec
pt
rA
Fo
Precedence of Operators in an Expression

y
nl
O
The table shows the precedence among the

se
different types of operators.

U
tre
Precedence Type of Operator
1 Arithmetic

en
2 Relational
3 C Logical
h
ec
pt
rA
Fo
The Parenthesis

y
nl
O
Sometimes, for certain formulas, the

se
programmer may need to override the

U
precedence rules.

tre
en
These rules can be overridden with the help of
C
h
parenthesis.
ec
pt

10/100 * ((basicSal+hra)-tax)
rA
Fo
Summary 1-2

y
nl
O
Operators are a set of symbols that help to

se
manipulate or perform some sort of function on

U
data.

tre
Operators can be classified into three types, namely,

en
arithmetic, relational, and logical operators.
Arithmetic operators help to manipulate numeric
C
h
data and perform common arithmetic operation on
ec

the data.
pt

Relational operators compare two or more values or


rA

expressions and always return either ‘True’ or ‘False’.


Fo
Summary 2-2

y
nl
O
Logical operators are used in situations where

se
multiple conditions need to be satisfied.

U
tre
In an equation involving all three types of operators,

en
arithmetic operators are evaluated first, followed by
C
relational operators, and finally logical operators.
h
ec

The programmer can specify the part of the equation


pt
rA

that needs to be solved first by using parenthesis.


Fo

You might also like