Professional Documents
Culture Documents
rA
pt
ec
h
C
en
Session 5 - Operators
tre
U
se
O
nl
y
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
expression
Fo
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
operators.
Fo
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
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
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
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
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
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
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
Equal to
rA
se
operators.
U
tre
Therefore, they are always evaluated from left
en
to right.
C
h
ec
pt
rA
Fo
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
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
se
logical operators.
U
tre
Precedence Operator
1 NOT
en
2 AND
3
C OR
h
ec
pt
rA
Fo
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
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
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
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