Thread: Chapter03
View Single Post
  #4 (permalink)  
Old October 8th, 2016, 12:03 AM
FittyFrank FittyFrank is offline
Registered User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2015
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default Ch. 3 Exercises

Hi all, I think the answer in the appendix to exercise 3.5 is incorrect.
Question:
By considering operator precedence, list the steps involved in the computation of the following expression:
resultVar += var1 * var2 + var3 % var4 / var5;

The precedence shown using parentheses in Appendix A is:
resultVar += (((var1 * var2) + var3) % (var4 / var5));

I believe the answer should be:
resultVar + ((var1 * var 2) + ((var3 % var4) / var5))

To me it seems as though the answer in the appendix gives preference to an addition operation over the % operation which is incorrect. It's late at night so I might just be sleepy, but feel free to take a look.
Reply With Quote