C++ Interview Questions

While it's usually okay to use lists like this one for orientation, it's best not to fall into the habit of learning to simply be able to "pass interviews". Most of your professional life will not be an interview, but a complicated mess of thoughts, discussions (often very passionate), arguments and frequent struggles to promote good ideas while at the same time respecting everyone's viewpoint in your team. Prepare yourself for that. And, above all, love what you do, never stop learning and always strive for excellence.

Also see these sample CV formats:


Language Features

  • What is a constructor? How many types of constructors do you know? How is each used?
  • What is a destructor?
  • When does object lifetime begin? When does it end? 
  • Does the compiler generate functions for an empty class? What are those?
  • What should you often implement for a class that has a pointer member?
  • What is the size of an empty class object? Why?
  • What is a reference? What is a pointer? What's the difference?
  • What are smart pointers? How many kinds of them do you know?
  • What is the difference between const int* p and int* const p?
  • What could you write instead of const int* const p?
  • What are the ways to pass objects to functions? Which is best when?
  • What is this pointer?
  • What does malloc() return?
  • What is the difference between malloc() and new?
  • What does delete p do for a null pointer p?
  • What does placement new do and where can it be useful?
  • What problems might we have with a pointer to void?
  • Objects of which types can be thrown as exceptions. Can they be of type int?
  • Should one throw exceptions from destructors?
  • What are access privileges?
  • Describe public vs private inheritance.
  • What is the difference between a struct and a class?
  • What are namespaces? Is it possible to use an empty namespace?
  • What is it about classes that can be a problem with unit testing?
  • How do C++ implementations typically achieve function overloading?
  • What is the purpose of extern "C"?
  • What are the core differences between Java and C++?
  • What does the keyword explicit mean?
  • What does the keyword friend mean?
  • What does the keyword inline mean? What might be its benefits and downsides?
  • What does the keyword mutable mean? Have you used it?
  • What does the keyword volatile mean? Why might it cause extra latency in code?
  • What does const qualifier mean in case of a function?
  • In which contexts can the keyword static be used and what does each mean?
  • What does dynamic_cast do? When is it best to use it?
  • How does dynamic_cast signal success or failure?
  • What does static_cast do? When is it best to use it?
  • Describe an equivalent for loop for a given while loop.
  • What is a POD? Where would you use it?
  • What is the main difference between POD and an object?
  • What is undefined behavior?

Abstraction

  • What are virtual functions? When did you last use them and for what?
  • What is polymorphism? What is it good for? How is it typically implemented?
  • What is the purpose of virtual destructors? When would you declare a destructor virtual?
  • What are pure virtual functions?
  • Can a pure virtual function have a body?
  • Can a template function be virtual?
  • Can constructors be virtual?
  • What is late binding?
  • What is dead code?

STL and Libraries

  • What is STL? Have you used it?
  • What container resembles a vector in being contiguous, but has an O(1) insertion?
  • What is the difference between a vector and a list?
  • What are performance characteristics of vector and list?
  • What is an iterator? Name some iterator types.
  • Name the main difference between Random Access Iterator and Bidirectional Iterator.
  • What kind of iterators do vector and map have?
  • Is adding at the end of a vector always fast?
  • What is the complexity of finding an element in a vector and in a map?
  • Do you know any other type of container that has better performance?
  • What is a hash table? Is there one in STL?
  • How can you make an object non-copyable?
  • Have you used boost?
  • Do you know any boost module that has similar functionality? Do you know how it works?
  • Implement a simple shared_ptr.

Applications

  • What is a thread?
  • What is a process?
  • How do processes and threads differ?
  • What does the fork() function do?
  • What inter-process communication mechanisms are there?
  • What is a race condition?
  • What is a deadlock? Give an example.
  • What is a livelock? Can you give an example?
  • How do you make a class thread safe? Where would you put the synchronization object?
  • How do you make it possible to use that object as a class member if the object is const?
  • How would you make sure to avoid deadlock and livelock?
  • What are command line arguments?
  • If your application crashes, how would you start to investigate the reason?
  • How would you investigate memory leaks in your application?