A comprehensive collection of medium-to-hard C++ interview questions and coding problems, organized by topic.
| # | Topic | Questions |
|---|---|---|
| 1 | C++ Basics | Pointers, references, casts, memory, UB, lvalues/rvalues, RVO/NRVO, compiler UB exploitation |
| 2 | OOP Concepts | Inheritance, polymorphism, virtual functions, RTTI, SOLID, EBO, devirtualisation |
| 3 | STL | Containers, iterators, algorithms, complexity, custom comparators, SSO, vector growth strategy |
| 4 | Templates & Generic Programming | Function/class templates, specialization, variadic templates, SFINAE, concepts, two-phase lookup, code bloat |
| 5 | Smart Pointers & Modern C++ | unique_ptr, shared_ptr, weak_ptr, move semantics, lambdas, guaranteed copy elision, control block internals |
| 6 | Concurrency & Multithreading | std::thread, mutexes, atomics, condition variables, memory model, false sharing, acquire-release CPU mapping |
| 7 | Data Structures & Algorithms | Linked lists, trees, graphs, sorting, dynamic programming, branch misprediction, cache-oblivious design |
| 8 | Design Patterns | Creational, structural, and behavioural patterns in C++, type erasure internals, policy-based design |
| 9 | Common Coding Problems | Classic interview coding challenges with C++ solutions, tricky UB quiz, aligned object pool |
| 10 | Memory Management | Stack vs heap, leaks, dangling pointers, placement new, allocators, pools, alignment, alloca, cache hierarchy |
| 11 | Exception Handling & Lambdas | Exception safety, noexcept, custom exceptions, lambda captures, zero-cost EH internals, std::function overhead |
| 12 | Ranges & Concepts (C++20) | Ranges library, views, lazy evaluation, pipe composition, projections, C++20 concepts, coroutines, modules |
Each file contains:
- A numbered table of contents
- Individual questions with difficulty ratings
- Detailed answers with explanations
- Compilable C++ code examples
Questions are aimed at software engineering interviews at mid-to-senior level.
All code snippets use C++17 or later (some examples use C++20 features). Compile with:
g++ -std=c++20 -Wall -Wextra -o example example.cpp