C++ Brain Teasers: Exercise Your Mind
Huge savings for students
Each student receives a 50% discount off of most books in the HSG Book Store. During class, please ask the instructor about purchase details.List Price: | |
Price: | |
You Save: |
Each puzzle in the book is a complete, seemingly simple C++ program, but can you figure out the output for each, or will the answers stump you? Most of the programs compile and have deterministic, though sometimes surprising, output. Some might, however, have undefined behavior, where anything can happen, including making demons fly out of your nose! Yet others might have unspecified behavior with output that is not completely deterministic; we just know nothing as bad as nasal demons will happen.
All puzzles are accompanied by detailed discussions, taking a look under the hood at what exactly is going on to help you understand more about C++'s unexpected behaviors, as well as fundamental concepts like initialization, overload resolution, and implicit conversions. For the non-deterministic cases, we'll explore some typical behaviors one can expect to see in practice, what causes them, and why they shouldn't be relied on.
After working through the book, you'll have tools and techniques to help you write better and safer code, and a better understanding of the fundamentals of the language, the background for some of C++'s apparent weirdness, and a better feel for identifying bugs and unsafe code in your own programs.
What You Need:
The book assumes basic knowledge of C++. If you want to run the programs yourself, you can use either a local C++ compiler or the online compilers at https: //godbolt.org.