The short answer: C++ interviews focus on how you manage resources and objects safely: pointers and references, the stack and heap, RAII and smart pointers, copy and move semantics (the rule of zero and the rule of five), virtual functions and destructors, const-correctness, templates and the STL, plus undefined behavior and concurrency for experienced roles. Interviewers like answers grounded in modern C++ (C++11 and later), which favors automatic resource management over manual new and delete. The C++ Core Guidelines, edited by Bjarne Stroustrup and Herb Sutter, are a good reference for the “right” answers. Below are the common questions with short answers and code.
Basics
“What’s the difference between a pointer and a reference?”
A pointer holds an address, can be null, can be reseated and needs dereferencing; a reference is an alias that must be initialized, can’t be null in valid code, and can’t be reseated. Use references for parameters that must refer to an object, pointers when “no object” is a valid state.
“What’s the difference between the stack and the heap?”
Stack memory holds local variables and is freed automatically when they go out of scope; it’s fast but limited. Heap memory is allocated dynamically and lives until it’s freed, which is why it needs an owner.
“What does const mean in different positions?”
const int* p is a pointer to a constant int; int* const p is a constant pointer; a const member function promises not to modify the object’s observable state.
Resource management
“What is RAII?”
Resource Acquisition Is Initialization: tie a resource (memory, a file, a lock) to an object’s lifetime, so the constructor acquires it and the destructor releases it, even when exceptions are thrown. The C++ Core Guidelines’ rule R.1 is: “Manage resources automatically using resource handles and RAII.”
{
std::lock_guard<std::mutex> lock(m); // locks here
counter++;
} // unlocks automatically here
“Which smart pointer should you use?”
std::unique_ptr: single owner, no overhead, movable but not copyable. The default choice.std::shared_ptr: shared ownership with reference counting.std::weak_ptr: a non-owning reference to ashared_ptrobject, used to break cycles.
The Core Guidelines advise: “Prefer unique_ptr over shared_ptr unless you need to share ownership” (R.21), and “Use make_unique() to make unique_ptrs” (R.23).
auto widget = std::make_unique<Widget>(42);
std::shared_ptr<Cache> cache = std::make_shared<Cache>();
“Why avoid raw new and delete?”
They make leaks and double frees easy, especially with exceptions. Rule R.11 says: “Avoid calling new and delete explicitly.”
Copy and move semantics
“What are the rule of zero and the rule of five?”
Rule of zero (C.20): “If you can avoid defining default operations, do.” Let members such as std::string, std::vector and smart pointers manage themselves. Rule of five (C.21): if you define or delete any of the copy constructor, copy assignment, move constructor, move assignment or destructor, define or delete them all.
“What is move semantics?”
Moving transfers a resource from one object to another instead of copying it, leaving the source in a valid but unspecified state. It uses rvalue references (T&&); std::move casts an object to an rvalue so it can be moved from.
std::vector<std::string> names = load();
std::vector<std::string> other = std::move(names); // no deep copy
Object-oriented features
“How do virtual functions work?”
They enable runtime polymorphism: calls through a base pointer or reference dispatch to the derived implementation, usually via a per-class table of function pointers (a vtable). Use override to let the compiler check overrides.
“Why should a base class destructor be virtual?”
If you delete a derived object through a base pointer and the destructor isn’t virtual, the derived destructor doesn’t run, which is undefined behavior. Guideline C.35: “A base class destructor should be either public and virtual, or protected and non-virtual.”
“What’s the difference between overloading and overriding?”
Overloading is several functions with the same name and different parameters, resolved at compile time; overriding is a derived class replacing a virtual function, resolved at runtime.
Templates and the STL
- “What are templates?” Code generated for each type it’s used with, enabling generic containers and algorithms at compile time.
- “vector vs list?”
std::vectorstores elements contiguously, with fast random access and cache-friendly iteration;std::listallows fast insertion anywhere but poor locality. Prefervectorby default. - “map vs unordered_map?”
std::mapis ordered (usually a balanced tree, O(log n));std::unordered_mapis a hash table with average O(1) lookups and no ordering. - “What is iterator invalidation?” Some operations (for example, inserting into a
vectorthat reallocates) invalidate existing iterators, pointers and references.
Undefined behavior and concurrency
- “Give examples of undefined behavior.” Reading uninitialized variables, out-of-bounds access, dereferencing null or dangling pointers, signed integer overflow and data races. Guideline ES.20: “Always initialize an object.”
- “What’s a data race and how do you prevent it?” Two threads access the same memory, at least one writes, without synchronization. Use mutexes (with
std::lock_guardorstd::scoped_lock), atomics, or avoid shared mutable state.
Coding exercises you might get
Reverse a linked list, implement a simple string class or a smart pointer (tests the rule of five), an LRU cache with unordered_map and list, or a thread-safe queue.
See also our software engineer interview questions, Java interview questions and Java 8 interview questions.
Frequently asked questions
What C++ questions are asked in interviews?
What is RAII in C++?
When should I use unique_ptr vs shared_ptr?
What is the rule of five?
Why should a base class destructor be virtual?
Sources
- Bjarne Stroustrup and Herb Sutter (editors), C++ Core Guidelines. Read on 1 October 2026.