FIT1051 Lecture Notes - Lecture 4: Boolean Expression

158 views4 pages
Week 4
Monday, 19 March 2018
10:12 AM
Order precedence:
Brackets come first, always.
Work from left to right
Equal sign is the only one from right to left (assignment)
o Assignment (=) has the lowest precedence of all
o A = b + c
o If equal wasn't the very lowest, it would happen before the plus.
o Right hand side must always be evaluated to a value, therefore equal sign must be of
lowest precedence to ensure.
int i1 = 1, i2 = 2, exp;
myWindow.clearOut();
exp = i1 + 7 + test2();
myWindow.writeOutLine(exp);
i1 = 1 + (2 + 3); //7
i1 = (1 + 2) + 3; //9
-----------------------
i1 = i2 = 21;
myWindow.writeOutLine(i2 = 21);
myWindow.writeOutLine(i1 + ", " + i2);
i1 = 5;
myWindow.writeOutLine(i1-- * i1--);
myWindow.writeOutLine(i1);
^i1-- value originally 5, decrements to 4
^i1-- value now 4, need to decrement to 3
>5 x 4 = 20
---------------
i1* = 5;
myWindow.writeOutLine(i1);
i1 = i1 x 5 (just a shortcut)
>compound operators
-----------
i1 = 7; //try 8 then 9 etc
myWindow.writeOutLine((i1 / 3) + ", " + (i1 % 3));
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents