Week4 Chapter4
Week4 Chapter4
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
Relational
Logical
Assignment
int float
10 + 11.8 = 21.8
Arithmetic operators: +, *
+ is the addition operator
* is the multiplication operator
They are both binary
Arithmetic operator:
This operator has two meanings:
subtraction operator (binary) e.g. 31 - 2
Arithmetic operator: %
The modulus (remainder) operator.
It computes the remainder after the first operand is divided by
the second
e.g. 5 % 2 is 1, 6 % 2 is 0
Relational operators
These perform comparisons and the result is what is
called a boolean: a value TRUE or FALSE
FALSE is represented by 0; anything else is TRUE
The relational operators are:
< (less than)
<= (less than or equal to)
> (greater than)
>= (greater than or equal to)
== (equal to)
!= (not equal to)
Logical operators
(also called Boolean operators)
Is it 17 - (8 * 2)
or (17 - 8) * 2 ?
== !=
and
lower precedence
or
=
Example: Left
associativity
3*8/4%4*5
Example: Right associativity
a += b *= c-=5
Precedence & associativity
Examples:
Z = 10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 *2 + 1 ?