Daily C++ Interview
Daily C++ Interview
Prepare yourself for your next interview one question a day
About the Book
This book helps you prepare for your next C++ technical interview if you are looking for an entry- or intermediate level position.
The questions are mostly not about edge cases and brain teasers but they cover the realistic knowledge you'll need to get a developer position in the C++ world.
The idea is that you take one question a day, you try to figure it out it on your own and then you check the answer in the book, plus the references.
The book covers topics such as:
- `auto` and type deduction
- The different usages of `static`
- Polymorphism, inheritance and virtual functions
- Lambda functions
- How to use the const qualifier
- Some best practices in modern C++
- References, universal references, a bit of a mixture
- Special function and the rules of how many
- The Standard Template Library
The different typical interview processes
- The Big Tech style interview process
- The shorter interview process
autoand type deduction
- Question 1: Explain auto type deduction!
Question 2: When can
autodeduce undesired types?
Question 3: What are the advantages of using
Question 4: What is the type of
myCollectionafter the following declaration?
- Question 5: What are trailing return types?
Question 6: Explain
Question 7: When to use
Question 8: Which data type do you get when you add two
staticand its different usages
Question 9: What does a
staticmember variable in C++ mean?
Question 10: What does a
staticmember function mean in C++?
Question 11: What is the
staticinitialization order fiasco?
- Question 12: How to solve the static initialization order fiasco?
- Question 9: What does a
Polymorphism, inheritance and virtual functions
- Question 13: What is the difference between function overloading and function overriding?
Question 14: What is a
Question 15: What is the
overridekeyword and what are its advantages?
- Question 16: Explain the concept of covariant return types and show a use-case where it comes in handy!
- Question 17: What is virtual inheritance in C++ and when should you use it?
- Question 18: Should we always use virtual inheritance? If yes, why? If not, why not?
- Question 19: What’s the output of the following sample program? Is that what you’d expect? Why? Why not?
- Question 20: Can you access the public and protected members and functions of a base class if you have private inheritance?
- Question 21: What is private inheritance used for?
Question 22: Can you call a
virtualfunction from a constructor or a destructor?
Question 23: What role does a
Question 24: Can we inherit from a standard container (such as
std::vector)? If so what are the implications?
- Question 25: What does a strong type mean and what advantages does it have?
- Question 26: Explain short-circuit evaluation
- Question 27: What is a destructor and how can we overload it?
- Question 28: What is the output of the following piece of code and why?
Question 29: How to use the
= deletespecifier in C++?
- Question 30: What are immediately invoked lambda functions?
- Question 31: What kind of captures are available for lambda expressions?
How to use the
constqualifier in C++
- Question 32: What is the output of the following piece of code and why?
Question 33: What are the advantages of using
Question 34: Is it a good idea to have
constmembers in a class?
Question 35: Does it make sense to return
constobjects by value?
Question 36: How should you return
constpointers from a function?
Question 37: Should functions return
Question 38: Should you take plain old data types by
constreference as a function parameter?
Question 39: Should you pass objects by
constreference as a function parameter?
- Question 40: Does the signature of a function declaration has to match the signature of the function definition?
Question 41: Explain what
constinitbring to C++?
Some best practices in modern C++
- Question 42: What is aggregate initialization?
- Question 43: What are explicit constructors and what are their advantages?
- Question 44: What are user-defined literals?
Question 45: Why should we use
Question 46: What advantages does
Question 47: What are the advantages of scoped
enums over unscoped
- Question 48: Should you explicitly delete unused/unsupported special functions or declare them as private?
- Question 49: How to use the = delete specifier in C++?
- Question 50: What is a trivial class in C++?
- Question 51: Explain the Resource acquisition is initialization (RAII) idiom
- Question 52: When should we use unique pointers?
- Question 53: What are the reasons to use shared pointers?
- Question 54: When to use a weak pointer?
Question 55: What are the advantages of
std::make_uniquecompared to the new operator?
- Question 56: Should you use smart pointers over raw pointers all the time?
- Question 57: When and why should we initialize pointers to nullptr?
References, universal references, a bit of a mixture
Question 58: What does
Question 59: What does
- Question 60: What is the difference between universal and rvalue references?
- Question 61: What is reference collapsing?
Question 62: When
constexprfunctions are evaluated?
Question 63: When should you declare your functions as
- Question 58: What does
- Question 64: What are concepts in C++?
- Question 65: What are the available standard attributes in C++?
- Question 66: What is 3-way comparison?
- Question 67: Explain what consteval and constinit bring to C++?
- Question 68: What are modules and what advantages do they bring?
Special function and the rules of how many?
- Question 69: Explain the rule of three
- Question 70: Explain the rule of five
- Question 71: Explain the rule of zero
Question 72: What does
- Question 73: What is a destructor and how can we overload it?
- Question 74: Should you explicitly delete unused/unsupported special functions or declare them as private?
- Question 75: What is a trivial class in C++?
- Question 76: What advantages does having a default constructor have?
Object oriented design, inheritance, polymorphism
- Question 77: What are the differences between a class and a struct?
- Question 78: What is constructor delegation?
- Question 79: Explain the concept of covariant return types and show a use-case where it comes in handy!
- Question 80: What is the difference between function overloading and function overriding?
Question 81: What is the
overridekeyword and what are its advantages?
- Question 82: Explain what is a friend class or a friend function
- Question 83: What are default arguments? How are they evaluated in a C++ function?
Question 84: What is
thispointer and can we delete it?
- Question 85: What is virtual inheritance in C++ and when should you use it?
- Question 86: Should we always use virtual inheritance? If yes, why? If not, why not?
- Question 87: What does a strong type mean and what advantages does it have?
- Question 88: What are user-defined literals?
- Question 89: Why shouldn’t we use boolean arguments?
- Question 90: Distinguish between shallow copy and deep copy
- Question 91: Are class functions taken into consideration as part of the object size?
- Question 92: What does dynamic dispatch mean?
- Question 93: What are vtable and vpointer?
- Question 94: Should base class destructors be virtual?
- Question 95: What is an abstract class in C++?
- Question 96: Is it possible to have polymorphic behaviour without the cost of virtual functions?
- Question 97: How would you add functionality to your classes with the Curiously Recurring Template Pattern (CRTP)?
- Question 98: What are the good reasons to use init() functions to initialize an object?
- Question 99: What is observable behaviour of code?
- Question 100: What are the characteristics of an ill-formed C++ program?
- Question 101: What is unspecified behaviour?
- Question 102: What is implementation-defined behaviour?
- Question 103: What is undefined behaviour in C++?
- Question 104: What are the reasons behind undefined behaviour’s existence?
- Question 105: What approaches to take to avoid undefined behaviour?
- Question 106: What is iterator invalidation? Give a few examples.
The Standard Template Library
- Question 107: What is the STL?
- Question 108: What are the advantages of algorithms over raw loops?
- Question 109: Do algorithms validate ranges?
- Question 110: Can you combine containers of different sizes?
Question 111: How is a
vector’s memory layout organized?
- Question 112: Can we inherit from a standard container (such as std::vector)? If so what are the implications?
- Question 113: What is the type of myCollection after the following declaration?
- Question 114: What are the advantages of const_iterators over iterators?
- Question 115: Binary search an element with algorithms!
- Question 116: What is an Iterator class?
- Question 117: Can you call a virtual function from a constructor or a destructor?
- Question 118: What are default arguments? How are they evaluated in a C++ function?
- Question 119: Can virtual functions have default arguments?
- Question 120: Should base class destructors be virtual?
- Question 121: What is the function of the keyword mutable?
- Question 122: What is the function of the keyword volatile?
- Question 123: What is an inline function?
- Question 124: What do we catch?
- Question 125: What are the differences between references and pointers?
Question 126: Which of the following variable declarations compile and what would be the value of
- Question 127: What will the line of code below print out and why?
- Question 128: Explain the difference between pre- and post-increment/decrement operators
- Question 129: What are the final values of a, b and c?
- Question 130: Does this string declaration compile?
- Question 131: What are Default Member Initializers in C++?
- Question 132: What is the most vexing parse?
- Question 133: Does this code compile? If yes, what does it do? If not, why not?
Question 134: What is
std::string_viewand why should we use it?
- Question 135: How to check if a string starts or ends with a certain substring?
- Question 136: What is RVO?
- Question 137: How can we ensure the compiler performs RVO?
- Question 138: What are the primary and mixed value categories in C++?
- Question 139: Can you safely compare signed and unsigned integers?
- Question 140: What is the return value of main and what are the available signatures?
- Question 141: Should you prefer default arguments or overloading?
- Question 142: How many variables should you declare on a line?
- Question 143: Should you prefer a switch statement or chained if statements?
- Question 144: What are include guards?
- Question 145: Should you use angle brackets(<filename>) or double quotes(“filename”) to include?
- Question 146: How many return statements should you have in a function?
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
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, 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.