Introduction
- How to use this book
- The C++ interview in 2026: what AI changed
- Interview formats you will encounter
- A note on seniority and difficulty tags
Part 1 — Types, deduction, and the type system
- Q1.1: Explain
autotype deduction - Q1.2: When can
autodeduce undesired types? - Q1.3: What are the advantages of using
auto? - Q1.4: What is the type of
myCollectionafter the following declaration? - Q1.5: What are trailing return types?
- Q1.6: Explain
decltype - Q1.7: When to use
decltype(auto)? - Q1.8: Why should we use
nullptrinstead ofNULLor0? - Q1.9: What are the primary and mixed value categories in C++?
- Q1.10: Can you safely compare signed and unsigned integers?
- Q1.11: What is deducing this?
Part 2 — const, references, and parameter passing
- Q2.1: What are the advantages of using
constlocal variables? - Q2.2: Is it a good idea to have
constmembers in a class? - Q2.3: Does it make sense to return
constobjects by value? - Q2.4: How should you return
constpointers from a function? - Q2.5: Should functions return
constreferences? - Q2.6: Should you take plain old data types by
constreference as a function parameter? - Q2.7: Should you pass objects by
constreference as a function parameter? - Q2.8: Does the signature of a function declaration have to match the signature of the function definition?
- Q2.9: What is the difference between universal and rvalue references?
- Q2.10: What is reference collapsing?
- Q2.11: What are the differences between references and pointers?
- Q2.12: What is
std::reference_wrapperand when is it useful? - Q2.13: When does binding a reference extend a temporary’s lifetime?
Part 3 — Classes, special functions, and the rules of N
- Q3.1: What are the differences between a class and a struct?
- Q3.2: What is constructor delegation?
- Q3.3: What are the different forms of initialisation in C++ and when does each apply?
- Q3.4: What is aggregate initialisation?
- Q3.5: What are explicit constructors and what are their advantages?
- Q3.6: What are default member initialisers in C++?
- Q3.7: What is the most vexing parse?
- Q3.8: What advantages does having a default constructor have?
- Q3.9: What is a destructor and how can you overload it?
- Q3.10: Explain the rule of three
- Q3.11: Explain the rule of five
- Q3.12: Explain the rule of zero
- Q3.13: What does the compiler generate — and what does it suppress?
- Q3.14: Distinguish between shallow copy and deep copy
- Q3.15: Should you explicitly
=deleteunused/unsupported special functions or declare them as private? - Q3.16: How to use the
= deletespecifier in C++? - Q3.17: What is a trivial class in C++?
- Q3.18: What are the good reasons to use
init()functions to initialise an object? - Q3.19: Why should you use
explicitfor conversion operators, not just constructors?
Part 4 — Static members, friends, and other class features
- Q4.1: What does a
staticmember variable in C++ mean? - Q4.2: What does a
staticmember function mean in C++? - Q4.3: Are class functions taken into consideration as part of the object size?
- Q4.4: Explain what a friend class or a friend function is
- Q4.5: What are default arguments? How are they evaluated in a C++ function?
- Q4.6: Can virtual functions have default arguments?
- Q4.7: What is the
thispointer and can youdelete this? - Q4.8: What is the function of the keyword
mutable? - Q4.9: What is three-way comparison (the spaceship operator)?
Part 5 — Move semantics and value categories
- Q5.1: What does
std::movemove? - Q5.2: What does
std::forwardforward? - Q5.3: What is
std::forward_likeand how does it differ fromstd::forward? - Q5.4: What is RVO?
- Q5.5: How can we ensure the compiler performs RVO?
- Q5.6: What is the “moved-from state” of an object, and what is its contract?
- Q5.7: What makes a type cheap to move? When does move equal copy?
Part 6 — Polymorphism and inheritance
- Q6.1: What is the difference between function overloading and function overriding?
- Q6.2: What is a
virtualfunction? - Q6.3: What is the
overridekeyword and what are its advantages? - Q6.4: What does dynamic dispatch mean?
- Q6.5: What are vtable and vpointer?
- Q6.6: What role does a
virtualdestructor play? - Q6.7: Can you call a
virtualfunction from a constructor or a destructor? - Q6.8: What is an abstract class in C++?
- Q6.9: What is
dynamic_castand why is it considered a code smell? - Q6.10: Explain the concept of covariant return types and show a use case where it comes in handy
- Q6.11: Can you access the public and protected members and functions of a base class if you have private inheritance?
- Q6.12: What is private inheritance used for?
- Q6.13: What is virtual inheritance in C++ and when should you use it?
- Q6.14: Should you always use virtual inheritance? If yes, why? If not, why not?
- Q6.15: Is it possible to have polymorphic behaviour without the cost of virtual functions?
- Q6.16: How would you add functionality to your classes with the Curiously Recurring Template Pattern (CRTP)?
- Q6.17: Can C++23’s deducing this replace CRTP for adding functionality?
Part 7 — Modern C++ idioms and best practices
- Q7.1: What are user-defined literals?
- Q7.2: What does a strong type mean and what advantages does it have?
- Q7.3: What advantages does
usinghave overtypedef? - Q7.4: What are the advantages of scoped enums over unscoped enums?
- Q7.5: Why should you avoid boolean arguments?
- Q7.6: How many variables should you declare on a line?
- Q7.7: Should you prefer a
switchstatement or chainedifstatements? - Q7.8: How many return statements should you have in a function?
- Q7.9: Should you prefer default arguments or overloading?
- Q7.10: What are include guards?
- Q7.11: Should you use angle brackets or double quotes for
#include? - Q7.12: What is the return type of
mainand what are the available signatures? - Q7.13: What are the available standard attributes in C++?
- Q7.14: What is
[[assume(expr)]]? - Q7.15: What is
[[nodiscard]]and how should you adopt it? - Q7.16: What are designated initialisers in C++20?
- Q7.17: What are immediately invoked lambda functions?
- Q7.18: What kind of captures are available for lambda expressions?
- Q7.19: What are
static operator()andstatic operator[]? - Q7.20: What are the key components of
and when would you usesteady_clockvssystem_clock? - Q7.21: Why is calling
now()directly bad for testability, and how do you fix it? - Q7.22: What are coroutines and what problem do they solve?
Part 8 — Templates, concepts, and compile-time C++
- Q8.1: Explain what
constevalandconstinitbring to C++ - Q8.2: When are
constexprfunctions evaluated? - Q8.3: What are concepts in C++?
- Q8.4: What is deducing this and how does the explicit object parameter work?
- Q8.5: How does deducing this replace CRTP and const-overload duplication?
- Q8.6: What is the difference between
if constexprandif consteval? - Q8.7: What is SFINAE, and when do you still reach for it after concepts?
- Q8.8: What are variable templates and when are they useful?
Part 9 — Smart pointers and resource management
- Q9.1: Explain the Resource Acquisition Is Initialisation (RAII) idiom
- Q9.2: When should we use unique pointers?
- Q9.3: What are the reasons to use shared pointers?
- Q9.4: When to use a weak pointer?
- Q9.5: What are the advantages of
std::make_sharedandstd::make_uniquecompared to thenewoperator? - Q9.6: How do custom deleters differ between
std::unique_ptrandstd::shared_ptr? - Q9.7: Should you use smart pointers over raw pointers all the time?
- Q9.8: When and why should we initialise pointers to
nullptr? - Q9.9: What is the cost of passing
std::shared_ptrby value? - Q9.10: How do factory functions returning
std::unique_ptrsupport polymorphism?
Part 10 — The Standard Library: containers, algorithms, ranges
- Q10.1: What is the STL?
- Q10.2: What are the advantages of algorithms over raw loops?
- Q10.3: Do algorithms validate ranges?
- Q10.4: What are ranges and views, at a high level?
- Q10.5: Can you combine containers of different sizes?
- Q10.6: How is a
vector’s memory layout organised? - Q10.7: What are the advantages of
const_iteratorover iterators? - Q10.8: Binary search an element with algorithms!
- Q10.9: What is an iterator class?
- Q10.10: What is
std::string_viewand why should you use it? - Q10.11: How to check if a string starts or ends with a certain substring?
- Q10.12: What is
std::spanand what does it replace? - Q10.13: Explain the differences between
std::mapandstd::unordered_map - Q10.14: When to use a list over a vector?
- Q10.15: Can you inherit from a standard container such as
std::vector? If so, what are the implications? - Q10.16: What are the algorithmic complexities of the most important algorithms?
- Q10.17: What is
std::flat_mapand when do you reach for it? - Q10.18: When would you choose
std::arrayoverstd::vector? - Q10.19: What is
std::mdspan? - Q10.20: What are
std::printandstd::println?
Part 11 — Error handling, observable behaviour, undefined behaviour
- Q11.1: What is observable behaviour of code?
- Q11.2: What are the characteristics of an ill-formed C++ program?
- Q11.3: What is unspecified behaviour?
- Q11.4: What is implementation-defined behaviour?
- Q11.5: What is undefined behaviour in C++?
- Q11.6: What are the reasons behind undefined behaviour’s existence?
- Q11.7: What approaches can you take to avoid undefined behaviour?
- Q11.8: What is the strict aliasing rule, and what types are exempt from it?
- Q11.9: What is the static initialisation order fiasco?
- Q11.10: How do you solve the static initialisation order fiasco?
- Q11.11: What is iterator invalidation? Give a few examples.
- Q11.12: When should you declare your functions as
noexcept? - Q11.13: What do you catch when you catch exceptions?
- Q11.14: What happens when a destructor throws?
- Q11.15: How can you propagate exceptions from a destructor safely?
- Q11.16: What are the exception safety guarantees?
- Q11.17: What is
std::expectedand when does it beat exceptions? - Q11.18: What are the monadic operations on
std::optionalandstd::expected?
Part 12 — Looking forward: C++26 and beyond
- Q12.1: What is pack indexing in C++26?
- Q12.2: What are contracts in C++26?
- Q12.3: What is reflection in C++26, at a high level?
- Q12.4: What is
std::execution(senders/receivers) trying to solve? - Q12.5: What is
std::inplace_vectorand when does it beatstd::vectororstd::array? - Q12.6: What is “erroneous behaviour” in C++26 and how does it differ from UB?
Part 13 — Read this code: capstone exercises
- Q13.1: What type do you get when you add two
bool? - Q13.2: Which of the following variable declarations compile and what would be the value of
a? - Q13.3: What does this signed/unsigned subtraction print?
- Q13.4: What is the output of this
const-overload code? - Q13.5: Does this string declaration compile?
- Q13.6: Does this code compile?
- Q13.7: What is the output of the following sample program?
- Q13.8: What happens when you
std::moveaconstobject? - Q13.9: Why does this function return a dangling reference?
- Q13.10: Why does this lambda capture cause undefined behaviour?
- Q13.11: What happens when you
push_backduring iteration? - Q13.12: What does passing by value do to a derived object?
- Q13.13: In what order do destructors run?
Appendix A — The 100-day schedule
Appendix B — Quick reference card
- Special member functions — the Hinnant table
- Value categories
- Smart pointer comparison
- Container complexity cheat sheet
constplacement cheat sheet- Move semantics quick reference