FIT1051 Lecture Notes - Lecture 4: Boolean Expression
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