About This Title

Pages: 100
Published: February 2024
ISBN: 9798888650516
In Beta

Skill Level Meter

C++ Brain Teasers

Exercise Your Mind

by Anders Schau Knatten

C++ is famous for getting all the default behaviors wrong and for sometimes making demons fly out of your nose. Through 25 puzzles, from the useful to the outright weird, we explore some of C++ ‘s most interesting quirks. How does initialization actually work? Do temporaries even exist? Why is `+!!”” ` a valid expression in C++ ? As you work through each puzzle, you will peel off some of the layers of complexity of C++ , getting a fundamental understanding of how the language works. This will help you write better code and recognize issues more easily while debugging.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $14.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal

This book is in Beta, final version expected Feb 2024

Beta Books: What do I get?


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.

Resources

Releases:

  • B2.0 2024/03/27
  • B1.0 2023/11/06

Contents & Extracts

Note: Contents and extracts of beta books will change as the book is developed.

  • Preface
    • How Many Degrees?
    • String Theory
    • Hack the Planet!
    • Going Global
    • A Destructive Relationship
    • Who’s Up First?
    • All Good Things Must Come to an End
    • Will It Move?
    • Counting Copies
    • A Strange Assignment
    • What’s the Time of Death?
    • A False Start
    • A Constant Struggle
    • Aristotle’s Sum of Parts
    • Back From the Future
    • An Overloaded Container
    • A Strong Point
    • Moving Out
    • A Little Sum Thing
    • Monsters on the Move
    • Sizing Up Some Characters
    • The Phantom Spaceship
    • Off to a Good Start
    • A Specialized String Theory
    • Weakly Typed, Strongly Puzzling

Author

Anders Schau Knatten has been a professional programmer since 2001, using a variety of languages. He is the author of the online C++ Quiz here and C++ on a Friday here and has spoken about C++ at conferences like CppCon, Meeting C++ , NDC TechTown, and others. Anders is on Twitter as twitter.com/@knatten/ and twitter.com/@CppQuiz/, as well as on mastodon.online/@knatten.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $14.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal

This book is in Beta, final version expected Feb 2024

Beta Books: What do I get?

Related Titles:

Skill Level Meter

About This Title

Pages: 100
Published: February 2024
ISBN: 9798888650516
Edition: 1
In Beta