[HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]
Moderator: admin
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
[HD Pg 123, Sec. 5.1.3 - postfix-and-prefix-for-the-exam]
Page 124 first rectangle,
c = \textbf{b *} a * (a++ - --b) * a * b
I wonder what was it suppose to be?
c = \textbf{b *} a * (a++ - --b) * a * b
I wonder what was it suppose to be?
-
- 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]
\textbf{b *} should actually be just b* but in bold.
Added to errata.
thank you for your feedback!
Added to errata.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- 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]
that being the case, I make it out to be -240.
-
- 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]
Did we evaluate a before b because Unary post-increment has higher precedence?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
Had we have
Code: Select all
c = 2 * (++a - b--) * a * b
-
- 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]
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.
-
- 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]
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.
-
- 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]
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.
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.
-
- 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]
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?
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?
-
- 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]
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.
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.
-
- 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]
But as it is now it is a bit confusing.
-
- 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]
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.
Who is online
Users browsing this forum: No registered users and 52 guests