Page 1 of 1

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

Posted: Thu Jan 24, 2019 3:31 pm
by OCAJO1
Page 124 first rectangle,

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

I wonder what was it suppose to be?

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

Posted: Thu Jan 24, 2019 8:13 pm
by admin
\textbf{b *} should actually be just b* but in bold.
Added to errata.
thank you for your feedback!

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

Posted: Fri Jan 25, 2019 1:04 pm
by OCAJO1
that being the case, I make it out to be -240.

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

Posted: Tue May 07, 2019 3:54 am
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?

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

Posted: Tue May 07, 2019 4:15 am
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.

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

Posted: Tue May 07, 2019 6:31 am
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.

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

Posted: Tue May 07, 2019 6:43 am
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.

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

Posted: Tue May 07, 2019 6:48 am
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?

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

Posted: Tue May 07, 2019 6:50 am
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.

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

Posted: Tue May 07, 2019 6:53 am
by flex567
But as it is now it is a bit confusing.

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

Posted: Tue May 07, 2019 6:54 am
by admin
Sure, will let the author know about it and may be he can improve.