C++ interview questions test memory management, templates, the STL, and object-oriented principles including polymorphism and inheritance. C++ (CPP) roles in games, finance, and systems software expect you to reason about performance and ownership, not just write code that compiles. This page covers 40 real C++ interview questions with answers across four formats: multiple choice, written answers, spoken responses, and live coding challenges, the same mix used in modern technical interviews.
Practice each question in your browser with no signup required. Answers stay hidden until you attempt the question: type, speak, or code your response first, then compare it against the model answer. Questions range from fundamentals for your first developer job to scenario-based questions for senior roles, so you can find the gaps in your knowledge before the real interview.
40 questions with answersLast updated: Oct 19, 2026
Choose a question. Pick any of the 40 questions. They mix multiple choice, written, spoken, and coding, the same mix a real interviewer uses.
Attempt your answer. Select a multiple-choice option, type your written response, record a spoken answer, or write code in the editor.
Reveal the model answer. Once you have attempted the question, the model answer unlocks so you can compare it with yours.
Move to the next question. Track how many questions you have attempted with the progress bar at the top of the page.
Take a mock interview. When you are ready, try a full mock technical interview on Plaicer with AI-driven follow-up questions.
C++ Interview Questions and Answers
0 of 40 attempted
1Multiple choice
How would you describe C++ and what programming paradigms does it support?
Attempt the question first to reveal the answer.
Answer
C++ extends C with object-oriented features (classes, inheritance, polymorphism) and generic programming (templates) while maintaining low-level control.
2Written answer
Explain how C++ builds on C while adding object-oriented and functional features
Attempt the question first to reveal the answer.
Answer
C++ extends C with object-oriented features including classes, inheritance, virtual functions, and polymorphism. It adds generic programming through templates, enabling type-safe code reuse without runtime overhead. C++ introduces new memory management with new/delete, RAII for resource management, and exceptions for error handling. While maintaining C's low-level features (pointers, manual memory control), C++ allows different programming styles: procedural (like C), object-oriented (classes and inheritance), generic (templates), and functional (lambdas, higher-order functions). This multi-paradigm approach makes C++ flexible for diverse applications.
3Spoken answer
Walk through how you would design a game character system using inheritance and polymorphism
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I created a base Character class with virtual methods for movement, attacking, and taking damage. Derived classes (Warrior, Mage, Rogue) overrode these methods for specific behavior. Movement might be different speeds; attacks varied by damage type and range. Taking damage applied class-specific effects (Warrior gains armor, Mage loses mana). The client code worked with Character pointers, calling methods polymorphically. This design made adding new character types easy without changing existing code.
4Coding
Implement a simple Vector2D class with overloaded operators for addition, subtraction, and dot product
class Vector2D {
private:
double x, y;
public:
Vector2D(double x = 0, double y = 0) : x(x), y(y) {}
// Implement operators and methods
};
Attempt the question first to reveal the answer.
Answer
class Vector2D {
private:
double x, y;
public:
Vector2D(double x = 0, double y = 0) : x(x), y(y) {}
Vector2D operator+(const Vector2D& other) const {
return Vector2D(x + other.x, y + other.y);
}
Vector2D operator-(const Vector2D& other) const {
return Vector2D(x - other.x, y - other.y);
}
double dot(const Vector2D& other) const {
return x * other.x + y * other.y;
}
};
5Multiple choice
Explain object-oriented programming and its core principles
Attempt the question first to reveal the answer.
Answer
OOP bundles data and methods into objects, uses inheritance for code reuse, polymorphism for flexibility, encapsulation for data protection, and abstraction for interface simplification.
6Written answer
Describe the core principles: encapsulation, inheritance, polymorphism, and abstraction
Attempt the question first to reveal the answer.
Answer
Encapsulation bundles data with methods and hides implementation details using access specifiers (private, public, protected). Inheritance allows derived classes to extend base classes, promoting code reuse and creating hierarchies. Polymorphism enables methods to behave differently based on object type through function overloading (compile-time) and virtual functions (runtime). Abstraction presents simplified interfaces while hiding complexity. Together, these create maintainable, extensible code where changes to implementation don't affect client code.
7Spoken answer
Describe a situation where you used templates to write generic code and how you handled edge cases
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I created a generic Queue template that worked with any copyable type. For move-only types (like unique_ptr), I specialized the template to use move semantics. I used SFINAE to enable certain methods only for types supporting specific operations. I provided partial specialization for container types. Template metaprogramming helped ensure compile-time type safety. Testing required instantiating the template with various types.
8Coding
Create an Animal base class with virtual methods, and Derived Dog and Cat classes
class Animal {
public:
virtual ~Animal() {}
virtual void speak() = 0;
// Add more virtual methods
};
Attempt the question first to reveal the answer.
Answer
class Animal {
public:
virtual ~Animal() {}
virtual void speak() const = 0;
};
class Dog : public Animal {
public:
void speak() const override { std::cout << "Woof!" << std::endl; }
};
class Cat : public Animal {
public:
void speak() const override { std::cout << "Meow!" << std::endl; }
};
9Multiple choice
What is a class and how does it differ from a structure in C++?
Attempt the question first to reveal the answer.
Answer
In C++, the only syntactic difference is default access: struct defaults to public, class defaults to private. Both support methods and inheritance.
10Written answer
Explain how classes bundle data and methods, and how access specifiers control visibility
Attempt the question first to reveal the answer.
Answer
Classes group related data (member variables) and operations (member functions) into a single unit. Access specifiers control visibility: private members are accessible only within the class, protecting internal state; public members define the interface for external code; protected members are accessible to derived classes. This separation enables encapsulation, allowing the class to maintain invariants and change internal implementation without affecting users.
11Spoken answer
Explain how you would implement RAII in a file handling class to ensure proper cleanup
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I created a File class that opened files in the constructor and closed them in the destructor. Reading/writing happened in methods that checked if the file was open. If reading failed, methods threw exceptions, and the destructor guaranteed cleanup even during exception unwinding. This RAII pattern ensured resources were never leaked. Users didn't need try-catch for cleanup; the destructor handled it.
12Coding
Implement a generic linked list template that works with any data type
template<typename T>
class LinkedList {
private:
struct Node { T data; Node* next; };
Node* head;
public:
LinkedList() : head(nullptr) {}
// Implement list operations
};
Attempt the question first to reveal the answer.
Answer
template<typename T>
class LinkedList {
private:
struct Node { T data; Node* next; };
Node* head;
public:
LinkedList() : head(nullptr) {}
~LinkedList() { while (head) { Node* temp = head; head = head->next; delete temp; } }
void push(const T& value) {
Node* newNode = new Node{value, head};
head = newNode;
}
bool pop() {
if (!head) return false;
Node* temp = head;
head = head->next;
delete temp;
return true;
}
};
13Multiple choice
How does encapsulation protect data and control access in object-oriented design?
Attempt the question first to reveal the answer.
Answer
Encapsulation hides internal state as private members and provides public interfaces (getters/setters) to control access and enforce class invariants.
14Written answer
Describe how private, public, and protected members implement encapsulation
Attempt the question first to reveal the answer.
Answer
Private members (data and methods) are inaccessible outside the class, protecting internal state. Public members form the official interface. Protected members allow derived classes to access and extend functionality. This hierarchy enforces encapsulation: clients use public methods (which validate input and maintain invariants), while implementation details remain private. Derived classes can access protected members for controlled extension.
15Spoken answer
Talk about a time you debugged a subtle memory issue related to virtual function calls
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I debugged a crash where calling a virtual function on a deleted object caused undefined behavior. Using a debugger, I found the pointer was deleted but still used elsewhere. I tracked the object lifetime and found the deletion happened earlier than expected. I used unique_ptr with custom deleters to track when objects were destroyed. Adding virtual destructors to base classes prevented this class of bugs.
16Coding
Write a ResourceManager class using unique_ptr and shared_ptr for memory management
Explain inheritance and how derived classes extend base class functionality
Attempt the question first to reveal the answer.
Answer
Derived classes inherit members and can override methods. Single and multiple inheritance are supported, though multiple inheritance requires careful design.
18Written answer
Explain single and multiple inheritance, and the issues multiple inheritance can create
Attempt the question first to reveal the answer.
Answer
Single inheritance derives from one base class, creating straightforward hierarchies. Multiple inheritance derives from multiple base classes, enabling combining different interfaces but causing ambiguity: if both parents have the same method, which is called? The diamond problem occurs when a grandparent class is inherited through two paths, duplicating its data. Virtual inheritance resolves this by sharing a single instance. Most modern design uses composition or interfaces (abstract base classes) instead of multiple inheritance due to complexity.
19Spoken answer
Describe how you would design a composable animation system using templates and iterators
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I created an Animation base template and specific animations (TranslateAnimation, RotateAnimation, FadeAnimation) derived from it. The AnimationSystem used a vector of Animation pointers and iterated through them calling update(). Animations could be composed in sequences using an AnimationSequence class that was also an Animation. This enabled flexible, reusable animation chains.
20Coding
Implement a Calculator class that throws custom exceptions for invalid operations
class DivisionByZero : public std::exception {
public:
const char* what() const noexcept { return "Division by zero"; }
};
class Calculator {
public:
double divide(double a, double b) {
// Implement with exception throwing
}
};
Attempt the question first to reveal the answer.
Answer
class DivisionByZero : public std::exception {
public:
const char* what() const noexcept { return "Division by zero"; }
};
class Calculator {
public:
double divide(double a, double b) {
if (b == 0) throw DivisionByZero();
return a / b;
}
};
21Multiple choice
Describe polymorphism and how it enables flexible, extensible code
Attempt the question first to reveal the answer.
Answer
Polymorphism enables writing code that works with base class references but executes derived class methods, allowing extensibility without modifying existing code.
22Written answer
Contrast compile-time (function/operator overloading) and runtime (virtual functions) polymorphism
Attempt the question first to reveal the answer.
Answer
Compile-time polymorphism through function/operator overloading is resolved at compile time based on argument types. Multiple functions with the same name but different signatures coexist. Runtime polymorphism through virtual functions uses vtables to select the correct method at runtime based on object type. Template specialization is another compile-time mechanism. Compile-time polymorphism is zero-cost but less flexible; runtime is more flexible but has vtable overhead. Choosing between them depends on whether the type is known at compile time.
23Spoken answer
Explain how you would use STL containers and algorithms to solve a data processing problem efficiently
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I used vector<int> to store data and stable_sort to sort by performance (keeping equal elements' order). I transformed results with transform() applying a filter function. I used find_if() to locate specific elements and copy_if() to extract a subset. STL algorithms are optimized and composable, making the code concise and efficient. I avoided manual loops.
24Coding
Implement a Complex number class with operator overloading for arithmetic
class Complex {
private:
double real, imag;
public:
Complex(double r = 0, double i = 0) : real(r), imag(i) {}
// Overload arithmetic operators
};
What role do virtual functions play in achieving runtime polymorphism?
Attempt the question first to reveal the answer.
Answer
Virtual functions use virtual tables (vtables) to store pointers to member functions, enabling dynamic dispatch where the correct method is called based on object type.
26Written answer
Explain how virtual functions work through virtual tables and enable runtime method selection
Attempt the question first to reveal the answer.
Answer
Classes with virtual functions maintain vtables mapping function names to pointers. When a virtual method is called on a base class pointer/reference, the program consults the object's vtable to find the actual method to execute. This enables calling derived class methods through base class references, achieving polymorphism. The first virtual function in a class adds a pointer to the vtable, increasing object size. Virtual destructors are crucial: without them, deleting a derived object through a base pointer won't call the derived destructor, causing resource leaks.
27Spoken answer
Walk through how you would handle exceptions in a financial calculation system to maintain consistency
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
Each transaction was atomic: validate input, execute, record. If any step threw, the transaction rolled back automatically through stack unwinding. I used unique_ptr for automatic cleanup during exceptions. I separated validation (which shouldn't throw) from execution. I caught specific exceptions at appropriate levels, not swallowing them. The account balance never ended in an inconsistent state.
28Coding
Use STL containers and algorithms to sort and filter a collection of products by price
How do templates enable generic programming and code reuse in C++?
Attempt the question first to reveal the answer.
Answer
Templates generate type-specific code at compile time, enabling writing algorithms and containers that work with any type without runtime overhead.
30Written answer
Describe template instantiation, specialization, and template metaprogramming
Attempt the question first to reveal the answer.
Answer
Templates are generic definitions that instantiate for specific types at compile time. Each template<typename T> function/class generates type-specific code. Template specialization allows providing custom implementations for specific types: partial specialization for type patterns, explicit specialization for exact types. Template metaprogramming uses templates to perform compile-time computations, generating code based on type properties. SFINAE (Substitution Failure Is Not An Error) uses template substitution failures to enable different code paths based on type traits, enabling sophisticated generic algorithms.
31Spoken answer
Describe how you would optimize a performance-critical loop using move semantics and modern C++
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I replaced copies with moves using move() and move semantics. I avoided unnecessary allocations by reserving vector capacity upfront. I used const references to avoid copying in function parameters. I eliminated temporaries by using expressions directly. Profiling showed a 3x speedup. Modern C++ features like auto, range-based for loops, and smart pointers made the code cleaner while being faster.
32Coding
Implement a File class using RAII to manage file handles safely
#include <fstream>
class File {
private:
std::ifstream file;
public:
File(const std::string& path) {
file.open(path);
if (!file) throw std::runtime_error("Cannot open file");
}
~File() { file.close(); }
// Add read methods
};
What is the Standard Template Library and what components does it provide?
Attempt the question first to reveal the answer.
Answer
STL includes containers (vector, map, set), algorithms (sort, find), iterators, and function objects enabling generic, efficient programming.
34Written answer
Explain the components of STL and how they work together for generic programming
Attempt the question first to reveal the answer.
Answer
STL has three main components: Containers (vector, list, map, set) store collections. Algorithms (sort, find, transform) operate on containers. Iterators connect them, providing a common interface for traversal. A container provides begin()/end() iterators; algorithms accept iterators and work with any container. This separation enables algorithms to work with any container without coupling. Functors and lambdas customize algorithm behavior. STL achieves generic programming without inheritance, using templates and iterators.
35Spoken answer
Talk about a time you encountered a diamond inheritance problem and how you resolved it
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I encountered diamond inheritance where an Aircraft inherits from both Vehicle and Weaponized, both inheriting from Equipment. This duplicated Equipment's data and methods. I used virtual inheritance: class Vehicle : virtual public Equipment. This ensured only one copy of Equipment existed in the hierarchy. The virtual base constructor had to be explicitly called.
36Coding
Implement a String class with move constructor and move assignment operator
How does exception handling in C++ manage errors and maintain program state?
Attempt the question first to reveal the answer.
Answer
Exceptions propagate up the call stack until caught. RAII (destructors) ensure cleanup during unwinding, maintaining program invariants.
38Written answer
Describe exception propagation, stack unwinding, and best practices for exception safety
Attempt the question first to reveal the answer.
Answer
When an exception is thrown, the program searches up the call stack for a matching catch block. During stack unwinding, local objects are destroyed (destructors called), ensuring cleanup. RAII (Resource Acquisition Is Initialization) ensures destructors free resources. Strong exception safety guarantees that operations succeed or have no effect. Basic exception safety guarantees the program remains valid but possibly changed. No-throw guarantee means the operation never throws. Best practices: catch by const reference, don't catch and ignore exceptions silently, use RAII for resource management, provide strong or basic exception safety guarantees.
39Spoken answer
Explain how you would implement a type-safe wrapper around a C library using classes and RAII
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I wrapped a C library's opaque pointer handle in a C++ class. The constructor called the C library's initialization, storing the handle. The destructor called cleanup. Methods wrapped C functions, translating between C++ types and C types. I used smart pointers to ensure cleanup even if exceptions occurred. This made the C library feel like idiomatic C++.
40Coding
Create a generic Pair template with a specialization for pointer types
template<typename T, typename U>
class Pair {
public:
T first; U second;
};
// Provide specialization for pointer types
template<typename T, typename U>
class Pair<T*, U*> {
// Specialized implementation
};
Attempt the question first to reveal the answer.
Answer
template<typename T, typename U>
class Pair {
public:
T first; U second;
};
template<typename T, typename U>
class Pair<T*, U*> {
public:
T* first; U* second;
~Pair() { delete first; delete second; }
};
Topics covered
C++ fundamentals: paradigms, how C++ builds on C, classes vs structs
Encapsulation and access specifiers
Inheritance: single, multiple, and the diamond problem
Polymorphism: virtual functions, vtables, compile-time vs runtime
How many C++ interview questions are on this page?
40 real C++ interview questions across four formats: multiple choice (10), written answer (10), spoken answer (10), and coding (10).
Do I need to sign up to practice?
No. All 40 questions and model answers are free with no signup. You attempt each question first, and the model answer unlocks once you have engaged.
Who are these C++ interview questions for?
Developers preparing for C++ technical interviews at any level, from first job to senior engineer roles. Questions cover fundamentals through real-world scenarios.
What topics do the C++ questions cover?
The questions cover object-oriented C++, including inheritance and polymorphism. They also test templates, the STL, and operator overloading. Other topics include memory ownership with RAII and smart pointers, move semantics, and exception handling.
Can I practice coding questions in the browser?
Yes. Coding questions include starter code in an in-browser editor, so you can write your solution without installing anything.
How often are the questions updated?
The question bank is reviewed regularly and updated to reflect current C++ interview patterns.
Can I take a full mock interview?
Yes. Plaicer's mock technical interview walks you through a realistic 30 to 45 minute interview with AI-driven follow-up questions.
Which C++ standard do the questions use?
Modern C++ (C++11 and later), including smart pointers, move semantics, and lambdas, alongside core OOP and templates.