Leanpub Header

Skip to main content

The C++ Interview Book

173 questions, from foundations to C++26

This book is 100% completeLast updated on 2026-07-31

173 C++ interview questions. Junior to Senior. auto to C++26. Every question has follow-ups, code samples, and cross-references. A 100-day study plan with spaced repetition gets you through them all. A code-reading capstone sharpens your skills under pressure. Not just the answers — the reasoning that survives the follow-up questions.

Minimum price

$14.99

$19.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
1 Previous Editionwith 519 Readers
New edition of Daily C++ Interview
About

About

About the Book

The C++ Interview Book is a comprehensive guide to the questions you will face in a C++ interview — from the basics every candidate must know to the C++23 and C++26 features that set you apart.

This is the second edition of Daily C++ Interview, completely restructured and expanded. The original 149 questions have been deduplicated, rewritten, and reorganised into 13 topical parts. Over 40 new questions have been added, covering deducing this, std::expected, std::forward_like, ranges, std::print, contracts, reflection, and more.

Every question includes:

- A difficulty tag (Junior, Mid, or Senior) so you can calibrate your preparation

- Follow-up questions an interviewer might ask — often harder than the main question

- Cross-references to related questions elsewhere in the book

- Code samples that compile and illustrate the point

The book also includes:

- A 100-day study schedule with built-in spaced repetition

- A code-reading capstone (Part 13) — 13 "what does this code do?" exercises that mirror real interview formats

- A quick reference card covering the Hinnant table, value categories, smart pointers, container complexity, const placement, and move semantics

Whether you are preparing for your first C++ role or brushing up before a senior-level interview loop, this book gives you not just the answers, but the reasoning behind them — the kind of understanding that survives follow-up questions.

Written by Sandor Dargo, a C++ developer and author of four other C++ books, drawing on years of interviewing, being interviewed, and writing about C++ at sandordargo.com.

Share this book

Previous Editions

Author

About the Author

Sandor Dargo

I am a C++ software craftsman with strong Python working in the tourism and hospitality industry and an enthusiastic blogger writing about coding, books, and the importance of stoic philosophy in a software developer's life.

I moved to software development from database operations which means that I don't just care about delivering a product as fast as possible, but I do understand the importance of stability and maintainability.

I'm passionate about delivering clean solutions, but I find even more important to help my teams to constantly raise the bar and to (re)focus on quality and clean code. I do this by explaining how high-quality work will help them in their individual careers, by introducing more meaningful development processes and automation and by teaching them industry best practices. 

Contents

Table of Contents

Introduction

  1. How to use this book
  2. The C++ interview in 2026: what AI changed
  3. Interview formats you will encounter
  4. A note on seniority and difficulty tags

Part 1 — Types, deduction, and the type system

  1. Q1.1: Explain auto type deduction
  2. Q1.2: When can auto deduce undesired types?
  3. Q1.3: What are the advantages of using auto?
  4. Q1.4: What is the type of myCollection after the following declaration?
  5. Q1.5: What are trailing return types?
  6. Q1.6: Explain decltype
  7. Q1.7: When to use decltype(auto)?
  8. Q1.8: Why should we use nullptr instead of NULL or 0?
  9. Q1.9: What are the primary and mixed value categories in C++?
  10. Q1.10: Can you safely compare signed and unsigned integers?
  11. Q1.11: What is deducing this?

Part 2 — const, references, and parameter passing

  1. Q2.1: What are the advantages of using const local variables?
  2. Q2.2: Is it a good idea to have const members in a class?
  3. Q2.3: Does it make sense to return const objects by value?
  4. Q2.4: How should you return const pointers from a function?
  5. Q2.5: Should functions return const references?
  6. Q2.6: Should you take plain old data types by const reference as a function parameter?
  7. Q2.7: Should you pass objects by const reference as a function parameter?
  8. Q2.8: Does the signature of a function declaration have to match the signature of the function definition?
  9. Q2.9: What is the difference between universal and rvalue references?
  10. Q2.10: What is reference collapsing?
  11. Q2.11: What are the differences between references and pointers?
  12. Q2.12: What is std::reference_wrapper and when is it useful?
  13. Q2.13: When does binding a reference extend a temporary’s lifetime?

Part 3 — Classes, special functions, and the rules of N

  1. Q3.1: What are the differences between a class and a struct?
  2. Q3.2: What is constructor delegation?
  3. Q3.3: What are the different forms of initialisation in C++ and when does each apply?
  4. Q3.4: What is aggregate initialisation?
  5. Q3.5: What are explicit constructors and what are their advantages?
  6. Q3.6: What are default member initialisers in C++?
  7. Q3.7: What is the most vexing parse?
  8. Q3.8: What advantages does having a default constructor have?
  9. Q3.9: What is a destructor and how can you overload it?
  10. Q3.10: Explain the rule of three
  11. Q3.11: Explain the rule of five
  12. Q3.12: Explain the rule of zero
  13. Q3.13: What does the compiler generate — and what does it suppress?
  14. Q3.14: Distinguish between shallow copy and deep copy
  15. Q3.15: Should you explicitly =delete unused/unsupported special functions or declare them as private?
  16. Q3.16: How to use the = delete specifier in C++?
  17. Q3.17: What is a trivial class in C++?
  18. Q3.18: What are the good reasons to use init() functions to initialise an object?
  19. Q3.19: Why should you use explicit for conversion operators, not just constructors?

Part 4 — Static members, friends, and other class features

  1. Q4.1: What does a static member variable in C++ mean?
  2. Q4.2: What does a static member function mean in C++?
  3. Q4.3: Are class functions taken into consideration as part of the object size?
  4. Q4.4: Explain what a friend class or a friend function is
  5. Q4.5: What are default arguments? How are they evaluated in a C++ function?
  6. Q4.6: Can virtual functions have default arguments?
  7. Q4.7: What is the this pointer and can you delete this?
  8. Q4.8: What is the function of the keyword mutable?
  9. Q4.9: What is three-way comparison (the spaceship operator)?

Part 5 — Move semantics and value categories

  1. Q5.1: What does std::move move?
  2. Q5.2: What does std::forward forward?
  3. Q5.3: What is std::forward_like and how does it differ from std::forward?
  4. Q5.4: What is RVO?
  5. Q5.5: How can we ensure the compiler performs RVO?
  6. Q5.6: What is the “moved-from state” of an object, and what is its contract?
  7. Q5.7: What makes a type cheap to move? When does move equal copy?

Part 6 — Polymorphism and inheritance

  1. Q6.1: What is the difference between function overloading and function overriding?
  2. Q6.2: What is a virtual function?
  3. Q6.3: What is the override keyword and what are its advantages?
  4. Q6.4: What does dynamic dispatch mean?
  5. Q6.5: What are vtable and vpointer?
  6. Q6.6: What role does a virtual destructor play?
  7. Q6.7: Can you call a virtual function from a constructor or a destructor?
  8. Q6.8: What is an abstract class in C++?
  9. Q6.9: What is dynamic_cast and why is it considered a code smell?
  10. Q6.10: Explain the concept of covariant return types and show a use case where it comes in handy
  11. Q6.11: Can you access the public and protected members and functions of a base class if you have private inheritance?
  12. Q6.12: What is private inheritance used for?
  13. Q6.13: What is virtual inheritance in C++ and when should you use it?
  14. Q6.14: Should you always use virtual inheritance? If yes, why? If not, why not?
  15. Q6.15: Is it possible to have polymorphic behaviour without the cost of virtual functions?
  16. Q6.16: How would you add functionality to your classes with the Curiously Recurring Template Pattern (CRTP)?
  17. Q6.17: Can C++23’s deducing this replace CRTP for adding functionality?

Part 7 — Modern C++ idioms and best practices

  1. Q7.1: What are user-defined literals?
  2. Q7.2: What does a strong type mean and what advantages does it have?
  3. Q7.3: What advantages does using have over typedef?
  4. Q7.4: What are the advantages of scoped enums over unscoped enums?
  5. Q7.5: Why should you avoid boolean arguments?
  6. Q7.6: How many variables should you declare on a line?
  7. Q7.7: Should you prefer a switch statement or chained if statements?
  8. Q7.8: How many return statements should you have in a function?
  9. Q7.9: Should you prefer default arguments or overloading?
  10. Q7.10: What are include guards?
  11. Q7.11: Should you use angle brackets or double quotes for #include?
  12. Q7.12: What is the return type of main and what are the available signatures?
  13. Q7.13: What are the available standard attributes in C++?
  14. Q7.14: What is [[assume(expr)]]?
  15. Q7.15: What is [[nodiscard]] and how should you adopt it?
  16. Q7.16: What are designated initialisers in C++20?
  17. Q7.17: What are immediately invoked lambda functions?
  18. Q7.18: What kind of captures are available for lambda expressions?
  19. Q7.19: What are static operator() and static operator[]?
  20. Q7.20: What are the key components of and when would you use steady_clock vs system_clock?
  21. Q7.21: Why is calling now() directly bad for testability, and how do you fix it?
  22. Q7.22: What are coroutines and what problem do they solve?

Part 8 — Templates, concepts, and compile-time C++

  1. Q8.1: Explain what consteval and constinit bring to C++
  2. Q8.2: When are constexpr functions evaluated?
  3. Q8.3: What are concepts in C++?
  4. Q8.4: What is deducing this and how does the explicit object parameter work?
  5. Q8.5: How does deducing this replace CRTP and const-overload duplication?
  6. Q8.6: What is the difference between if constexpr and if consteval?
  7. Q8.7: What is SFINAE, and when do you still reach for it after concepts?
  8. Q8.8: What are variable templates and when are they useful?

Part 9 — Smart pointers and resource management

  1. Q9.1: Explain the Resource Acquisition Is Initialisation (RAII) idiom
  2. Q9.2: When should we use unique pointers?
  3. Q9.3: What are the reasons to use shared pointers?
  4. Q9.4: When to use a weak pointer?
  5. Q9.5: What are the advantages of std::make_shared and std::make_unique compared to the new operator?
  6. Q9.6: How do custom deleters differ between std::unique_ptr and std::shared_ptr?
  7. Q9.7: Should you use smart pointers over raw pointers all the time?
  8. Q9.8: When and why should we initialise pointers to nullptr?
  9. Q9.9: What is the cost of passing std::shared_ptr by value?
  10. Q9.10: How do factory functions returning std::unique_ptr support polymorphism?

Part 10 — The Standard Library: containers, algorithms, ranges

  1. Q10.1: What is the STL?
  2. Q10.2: What are the advantages of algorithms over raw loops?
  3. Q10.3: Do algorithms validate ranges?
  4. Q10.4: What are ranges and views, at a high level?
  5. Q10.5: Can you combine containers of different sizes?
  6. Q10.6: How is a vector’s memory layout organised?
  7. Q10.7: What are the advantages of const_iterator over iterators?
  8. Q10.8: Binary search an element with algorithms!
  9. Q10.9: What is an iterator class?
  10. Q10.10: What is std::string_view and why should you use it?
  11. Q10.11: How to check if a string starts or ends with a certain substring?
  12. Q10.12: What is std::span and what does it replace?
  13. Q10.13: Explain the differences between std::map and std::unordered_map
  14. Q10.14: When to use a list over a vector?
  15. Q10.15: Can you inherit from a standard container such as std::vector? If so, what are the implications?
  16. Q10.16: What are the algorithmic complexities of the most important algorithms?
  17. Q10.17: What is std::flat_map and when do you reach for it?
  18. Q10.18: When would you choose std::array over std::vector?
  19. Q10.19: What is std::mdspan?
  20. Q10.20: What are std::print and std::println?

Part 11 — Error handling, observable behaviour, undefined behaviour

  1. Q11.1: What is observable behaviour of code?
  2. Q11.2: What are the characteristics of an ill-formed C++ program?
  3. Q11.3: What is unspecified behaviour?
  4. Q11.4: What is implementation-defined behaviour?
  5. Q11.5: What is undefined behaviour in C++?
  6. Q11.6: What are the reasons behind undefined behaviour’s existence?
  7. Q11.7: What approaches can you take to avoid undefined behaviour?
  8. Q11.8: What is the strict aliasing rule, and what types are exempt from it?
  9. Q11.9: What is the static initialisation order fiasco?
  10. Q11.10: How do you solve the static initialisation order fiasco?
  11. Q11.11: What is iterator invalidation? Give a few examples.
  12. Q11.12: When should you declare your functions as noexcept?
  13. Q11.13: What do you catch when you catch exceptions?
  14. Q11.14: What happens when a destructor throws?
  15. Q11.15: How can you propagate exceptions from a destructor safely?
  16. Q11.16: What are the exception safety guarantees?
  17. Q11.17: What is std::expected and when does it beat exceptions?
  18. Q11.18: What are the monadic operations on std::optional and std::expected?

Part 12 — Looking forward: C++26 and beyond

  1. Q12.1: What is pack indexing in C++26?
  2. Q12.2: What are contracts in C++26?
  3. Q12.3: What is reflection in C++26, at a high level?
  4. Q12.4: What is std::execution (senders/receivers) trying to solve?
  5. Q12.5: What is std::inplace_vector and when does it beat std::vector or std::array?
  6. Q12.6: What is “erroneous behaviour” in C++26 and how does it differ from UB?

Part 13 — Read this code: capstone exercises

  1. Q13.1: What type do you get when you add two bool?
  2. Q13.2: Which of the following variable declarations compile and what would be the value of a?
  3. Q13.3: What does this signed/unsigned subtraction print?
  4. Q13.4: What is the output of this const-overload code?
  5. Q13.5: Does this string declaration compile?
  6. Q13.6: Does this code compile?
  7. Q13.7: What is the output of the following sample program?
  8. Q13.8: What happens when you std::move a const object?
  9. Q13.9: Why does this function return a dangling reference?
  10. Q13.10: Why does this lambda capture cause undefined behaviour?
  11. Q13.11: What happens when you push_back during iteration?
  12. Q13.12: What does passing by value do to a derived object?
  13. Q13.13: In what order do destructors run?

Appendix A — The 100-day schedule

Appendix B — Quick reference card

  1. Special member functions — the Hinnant table
  2. Value categories
  3. Smart pointer comparison
  4. Container complexity cheat sheet
  5. const placement cheat sheet
  6. Move semantics quick reference

Appendix C — Topic index

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub