Answers to Exercises

1.The correct answer is: “Who knows?” If you said “30”, you forgot that the loop variable values are from 0 through 4, rather than from 1 through 5. On the other hand, if you said “20”, you had the right total of the numbers 0, 2, 4, 6, and 8, but didn't notice that the variable Result was never initialized. Of course, adding anything to an unknown value makes the final value unpredictable. Many current compilers, unfortunately not including the one on the CD in the back of this book, are capable of warning you about such problems. If you're using a compiler that supports such warnings, I recommended that you enable them because that is the easiest way to find such errors, especially in a large program. Unfortunately, a compiler ...

Get C++: A Dialog Programming with the C++ Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.