You are on page 1of 16

Computer Operators

Arithmetic, Relational, & Logical Operators


Computer Operators:Processing data
For the programmer to instruct computers to
process mathematical computations and logical
operations, they would have to use symbols that
computer can understand.
Computer Operators: Arithmetic

Arithmetic operators include operations such


as addition, subtraction, multiplication,
division, and modulo
Operation Symbol Example Explanation
Multiplication * A*B Multiply the value of Variable A to the value of
variable B
Division / X/Y Divide the value of variable X by the value of
variable Y
Addition + int1 + int2 Add the value of variable int1 to the value of variable
int2
Subtraction - A–B Subtract the value of Variable B to the value of
variable A

Modulo % num1 % num2 Returns the remainder of dividing the value of


variable num1 by the value of variable num2

Exponentiation ^ C^2 Multiply the value of variable C twice


examples
Mathematical Expression Computer Expression
• 3xy •3*x*y
• (x * x) + (y * y)
• X2 + y2
• X ^2 + y^2
• (3 * x) / (y*y*y)
• 3x/y3
• (3*x) / (y^3)
Computer Operators: Relational

a relational operator is used to test the


relation between two entities.
Operation Symbol Example Explanation
Greater than > A>B the value of Variable A is
greater than the value of
variable B
Less than < X<Y the value of variable X is less
than the value of variable Y
Equal to == int1 == int2 the value of variable int1 is
equal to the value of variable
int2
Not equal to != or <> net != gross the value of Variable net is not
equal to the value of variable
gross
Operation Symbol Example Explanation
Greater than >= pay1 >= pay2 the value of Variable pay1 is
or equal to greater than or equal to the
value of variable pay2
Less than <= age1 <= age2 the value of variable age1 is less
or equal to than or equal to the value of
variable age2
Assignment = X=5 assigns the value of its right-
operator hand operand to a variable x
a logical operator is a symbol or word used to
connect two or more expressions

such that the value of the compound expression


produced depends only on that of the original
expressions and on the meaning of the operator
Symbols Meaning explanation
&& AND both conditions should be TRUE
before the resulting data could be
TRUE, otherwise the resulting data will
be FALSE
|| OR if either of the two value is True
then the resulting data is True
otherwise, the resulting values is
FALSE
! NOT the other hand reverses the
value of the given
statement, a True will become
False and vice versa.
AND
both conditions should be
TRUE && TRUE TRUE
TRUE before the resulting
data could be TRUE
TRUE && FASLE FALSE

otherwise the resulting data


FALSE && TRUE FALSE
will be FALSE
FALSE && FALSE FALSE
OR
if either of the two value is
TRUE || TRUE TRUE
True then the resulting data is
True otherwise,
TRUE || FASLE TRUE

the resulting values is FALSE


FALSE || TRUE TRUE

FALSE || FALSE FALSE


the other hand reverses the
value of the given NOT

statement, ! TRUE FALSE

a True will become False and ! FALSE TRUE


vice versa.
Order of Operation

Operator precedence specifies the order of


how operators are evaluated and performed
one after the other
X= 10 – 2 + 3 * (6 % 2)
X= 10 – 2 + 3 * (6 % 2)
X= 10 – 2 + 3 * 0
X= 10 – 2 + 3 * 0
X= 10 – 2 + 0
X= 10 – 2 + 0
X= 8 + 0
X= 8 + 0
X= 8

You might also like