📖 Book · cpp core · high

🪤 C++ Gotchas & Trick Questions

Guess-the-output traps, and the rule behind each one

The growing collection of C++ trap questions interviewers use to tell memorisation from understanding: new int vs new int() vs new int(5), () vs {} and the most vexing parse, signed/unsigned and overflow, dangling references and iterator invalidation, virtual-call-in-constructor, slicing, name hiding, and 0/NULL/nullptr. Well-defined examples run live; the undefined ones are flagged as UB instead of pretending an output is canonical. Each trap ends in the one rule that explains it.

7 chapters▶ runnable code✦ in-depth animation

What this book covers

  1. 01How to survive a trap question
  2. 02Initialization traps
  3. 03Integers & undefined behaviour
  4. 04Lifetime & dangling traps
  5. 05Polymorphism traps
  6. 06Overloads & conversions
  7. 07The rules behind every trap

Read it in full — runnable C++ + step-through animations

Every chapter of C++ Gotchas & Trick Questions ships complete, editable code you compile and run in the browser, plus the same in-depth animations as the lessons.