[HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

[HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by OCAJO1 »

Page 124 first rectangle,

c = \textbf{b *} a * (a++ - --b) * a * b

I wonder what was it suppose to be?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by admin »

\textbf{b *} should actually be just b* but in bold.
Added to errata.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by OCAJO1 »

that being the case, I make it out to be -240.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by flex567 »

We start with putting the values of the variables in the expression from left to right. Since the
value of a at the beginning of the evaluation is 2, the expression becomes:
c = 2 * (a++ - --b) * a * b
Did we evaluate a before b because Unary post-increment has higher precedence?

Had we have

Code: Select all

c = 2 * (++a - b--) * a * b
We would first evaluate b?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by admin »

No, only the values of the terms of the expression are being worked out in steps 1 to 4. This happens from left to right (evaluation order section 5.1.6)). Once the values of the terms is determined, the expression will be evaluated at step 5 using rules of precedence.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by flex567 »

You are now saying that the evaluation order comes first and after that rules of precedence are applied. But in the book on page 131 the opposites is stated:
Once an expression is grouped in accordance with the rules of precedence and associativity, the
process of evaluation of the expression starts.

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by admin »

The book is correct. Grouping is indeed done using precedence and associativity. I was trying to explain from another perspective but it turned out to be even more confusing.
I am not sure I can explain this better, sorry.
Paul.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by flex567 »

Both explanations are from the book.
One is in the postfix and prefix for the exam chapter.
Another one is 5.1.6 Operator precedence and evaluation of expressions

Will you fix it?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by admin »

Neither of the explanations are wrong or contradictory. The one in postfix and prefix section are just steps that can help you evaluate an expression of that kind quickly.
Expression evaluation is not a trivial thing. So, a set of simple steps that will work for the purpose of the exam may fail at a complicated expression that is not required for the exam.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by flex567 »

But as it is now it is a bit confusing.

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]

Post by admin »

Sure, will let the author know about it and may be he can improve.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests