# 04operatorsSmall - Lecture Set 4 Evaluation Order Today...

This preview shows pages 1–3. Sign up to view the full content.

1 CMSC 131 Spring 2007 Jan Plane (adapted from Bonnie Dorr) Lecture Set 4: Evaluation Order Today: c More assignment operators c Precedence and short- circuiting CMSC 131 Spring 2007 Jan Plane (adapted from Bonnie Dorr) 1 Expressions c Java “phrases” that yield values e.g. x x + 1 - y foo.equals (“cat”) c Expressions have values (int, boolean, etc.) c Expressions can be assigned to variables, appear inside other expressions, etc. CMSC 131 Spring 2007 Jan Plane (adapted from Bonnie Dorr) 2 Expressions and Side Effects c Some expressions can also alter the values of variables e.g. x=1 c x=1 is an expression? c Yes! c Value is result of evaluation right-hand side of = c It also alters the value of x c Such alterations are called side effects

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 CMSC 131 Spring 2007 Jan Plane (adapted from Bonnie Dorr) 3 Are the Following Legal? c int x, y; x = y = 1; Yes. Result assigns 1 to x and to y c int x = 0, y = 1; boolean b = false; if (b = (x <= y)){ x = y; } Yes. Result assigns true to b and 1 to x CMSC 131 Spring 2007 Jan Plane (adapted from Bonnie Dorr) 4 Other Expressions with Side Effects c Java includes abbreviations for common forms of assignment c Example: increment operations (Basically equivalent to x = x + 1 ++ x “Pre-increment” Increments x, returns the new value of x x++ “Post-increment” In crements x, returns the old value of x c Same or Different c x == x++ c x == ++x c Compare c x++ * y++ c ++x * ++y c ++x * y++ c x++ * ++y always true never true CMSC 131 Spring 2007 Jan Plane (adapted from Bonnie Dorr)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

04operatorsSmall - Lecture Set 4 Evaluation Order Today...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online