**Tom Kelliher, CS 116**

**Oct. 18, 2000**

Nothing new. Should have read up to 5.4.

Scope and access.

- Arithmetic operators.
- Logical operators.
- Return exam.

Logical operations, assignments, statements.

Suppose we know the following:

int i = 5; int j = -3; int k = 12;What are the values of the following expressions?

k - i * 2 i - 4 - j 4 / i * 5 i - 2 * k + jWhy?

How can we change the order of evaluation?

- Binary operators:
`+`

,`-`

,`*`

,`/`

,`%`

.- Precedence?
- Associativity?
- Type matters.
- No mixed-type operations.
Implicit type conversion. ``Smaller'' to ``larger'' types.

- Explicit type conversion with casts. Must be used when converting
larger to smaller types.
Casts are

*unary*operators.Example: generating a random integer from 1 to 10 (inclusive).

`Math.random()`

generates a random double such that . How can we use it to solve this problem?

- Precedence?
- Unary operators:
`-`

,`++`

,`--`

(and casts).Use increment and decrement judiciously.

Unary arithmetic operators have higher precedence than binary.

Associativity?

`abs()`

, `ceil()`

, `floor`

.

Comparison and boolean operators.

`<`

, `<=`

, `==`

, `!=`

, `>`

, `>=`

.

- Lower precedence than binary arithmetic operators.
Equality, inequality one level below others.

- Associate left-to-right.
- Take numeric arguments. Return a
`boolean`

.Why is

`0.0 < x < 1.0`

illegal?

Examples. Assume:

int n = 3; double x = 4.8;Evaluate (explain):

n < 3 n <= 3 n < x (n + 3) == 2 2 * n != x - 1.0 n >= n n / 4 > 0 n >= n == n < 3

- Take
`boolean`

argument(s). Return a`boolean`

value. - Binary:
`&&`

,`||`

.Lower precedence than equality, inequality.

Associate?

- Unary:
`!`

.Unary precedence.

Associate?

- Deriving the
*truth tables*.

Tue Oct 17 19:20:01 EDT 2000