C++ Software Engineer Interview Questions & Answers
40 questions for C++ Software Engineer interviews — 3 easy, 32 medium, 5 hard.
About the C++ Software Engineer role
A C++ software engineer designs and builds features for large products such as browsers, databases, networking software, CAD tools and cloud infrastructure. They own modules end to end, write modern C++ with smart pointers and templates, review code and improve performance. Interviews combine data structures and algorithms, object-oriented design, modern C++ questions and debugging scenarios. Engineers with two to five years of experience commonly hold this title.
After calling std::move on a string, a teammate prints it and sees an empty value. Is this a bug?
Show answer
What is a deadlock and how do you prevent it?
Show answer
A function taking a Money object is silently called with an int and gives wrong results. What is happening?
Show answer
Write a variadic function that sums any number of arguments and one that prints them.
Show answer
Why are templates usually defined in header files?
Show answer
Should a Car class inherit from Engine or contain an Engine? Explain your choice.
Show answer
What is the erase-remove idiom and what replaced it in C++20?
Show answer
Write a custom hash so a struct can be used as a key in std::unordered_map.
Show answer
Show the copy-and-swap idiom and explain why it gives strong exception safety.
Show answer
An asynchronous callback crashes intermittently. It is a lambda that captures local variables by reference. Explain the problem and fix.
Show answer
Explain the rule of three, rule of five and rule of zero.
Show answer
When do you need the typename keyword inside a template?
Show answer
How would you choose between exceptions, error codes and std::expected for error handling?
Show answer
Why should a base class have a virtual destructor?
Show answer
A program does millions of lookups in a std::map with string keys and is slow. How would you speed it up?
Show answer
You need a container that holds ints, strings and doubles together. Which approach would you choose?
Show answer
What does noexcept mean and why should move constructors be noexcept?
Show answer
What is the diamond problem and how does virtual inheritance solve it?
Show answer
What are std::optional, std::variant and std::any?
Show answer
What is template argument deduction and class template argument deduction?
Show answer
What does the C++20 ranges library add?
Show answer
What is the difference between push_back and emplace_back?
Show answer
What is object slicing?
Show answer
Write a C++20 concept and use it to constrain a function.
Show answer
What kinds of constructors does C++ have?
Show answer
Design a class structure for UPI, card and net banking payments in a checkout system.
Show answer
How would you explain polymorphism to a junior developer who has just joined your team?
Show answer
A teammate complains that a template function produces hundreds of lines of compiler errors when misused. How do you improve this?
Show answer
A function returns a string_view and callers sometimes print garbage. What is the likely bug?
Show answer
What are type traits and how does if constexpr use them?
Show answer
A generic maxOf template gives wrong results when called with two C-style string literals. Why, and how do you fix it?
Show answer
What is the difference between full and partial template specialization?
Show answer
Describe a situation where you disagreed with a senior engineer about a design decision.
Show answer
How do you handle a tight deadline when the C++ code you need to change is complex?
Show answer
A generic average function must accept only numeric types. How would you enforce that?
Show answer
Sorting a vector of large objects is slow. What can you do?
Show answer
Tell me about a time you found a difficult bug in your C++ code.
Show answer
What are the main components of the Standard Template Library?
Show answer
How do virtual functions work internally?
Show answer
Frequently asked questions
What does a C++ Software Engineer do?
A C++ software engineer designs and builds features for large products such as browsers, databases, networking software, CAD tools and cloud infrastructure. They own modules end to end, write modern C++ with smart pointers and templates, review code and improve performance. Interviews combine data structures and algorithms, object-oriented design, modern C++ questions and debugging scenarios. Engineers with two to five years of experience commonly hold this title.
Which skills are tested in a C++ Software Engineer interview?
Expect questions on Modern C++17/20, Templates, Code review, CMake builds, Performance tuning. Most rounds also ask you to explain a project and solve one practical problem live.
How do I prepare for a C++ Software Engineer interview?
Revise Modern C++ (C++11 to C++23), Templates and Generic Programming, Standard Template Library (STL), Object-Oriented Programming in C++ first using the topic sheets, practise the questions on this page aloud, then do one full mock interview to practise timing.