C/C++ Interview Cheatsheet#
This page is a curated, question-indexed map into the rest of the cheatsheet. Each entry below is a question you are likely to see in a C or C++ interview, followed by a link that jumps directly to the section of the notes that answers it. It is intentionally a navigation layer — the actual explanations, code, and caveats live in the linked sections.
Use it two ways:
Drilling a topic: pick a group (e.g. Templates & Generics) and walk every question in it.
Quick review before an interview: read the questions, and for any you cannot confidently answer in one or two sentences, click through.
Memory & Resource Management#
What is RAII, and why is it the cornerstone of modern C++ resource management? → cpp/cpp_raii: RAII Wrapper
How does RAII interact with exception safety (basic / strong / nothrow guarantees)? → cpp/cpp_raii: Exception Safety Guarantees
What happens when a constructor throws after partial resource acquisition? → cpp/cpp_raii: Constructor Failure and Exception Safety
Compare
std::lock_guard,std::unique_lock, andstd::scoped_lock. → cpp/cpp_raii: Lock-Based RAIIWhen does
std::unique_ptrmake sense vs.std::shared_ptr? → cpp/cpp_smartpointers: std::unique_ptr: Exclusive OwnershipWhat problem does
std::weak_ptrsolve? → cpp/cpp_smartpointers: std::weak_ptr: Non-Owning ObserverWhy prefer
std::make_unique/std::make_sharedover rawnew? → cpp/cpp_smartpointers: std::make_unique and std::make_sharedWhat are common smart-pointer pitfalls (e.g. cycles, double ownership)? → cpp/cpp_smartpointers: Common Pitfalls
Why does memory alignment matter, and how is struct padding computed? → c/c_memory: Structure Alignment and Padding
Move Semantics & Value Categories#
What are the special member functions, and when are they implicitly defined or deleted? → cpp/cpp_move: Special Member Functions
Explain the Rule of Zero, Three, and Five. → cpp/cpp_move: Rule of Zero · Three · Five
What are lvalues, rvalues, xvalues, prvalues? → cpp/cpp_move: Value Categories
How does
std::forwardachieve perfect forwarding, and why is it needed? → cpp/cpp_move: Perfect ForwardingWhat state is a moved-from object left in, and what can you safely do with it? → cpp/cpp_move: Moved-From State
Why should move constructors typically be
noexcept? → cpp/cpp_move: Conditional noexceptemplace_backvs.push_back— when is there a real difference? → cpp/cpp_move: Emplace vs Insert
Templates & Generics#
How does template specialization differ from overloading? → cpp/cpp_template: Template Specialization
What are variadic templates and fold expressions? → cpp/cpp_template: Variadic Templates and Parameter Packs · Fold Expressions
What is SFINAE, and how do C++20 concepts replace most of it? → cpp/cpp_template: SFINAE and Type Constraints · Defining Concepts
What is CRTP and when would you use it? → cpp/cpp_template: CRTP
How does a
requiresclause constrain a template, and how does it compose with&&/||? → cpp/cpp_requires: Basic Requires Clause · Conjunction · Disjunctionrequiresvs.if constexpr— when to reach for which? → cpp/cpp_requires: Requires vs if constexprWhat are reference collapsing rules, and why do they matter for forwarding references? → cpp/cpp_basic: Reference Collapsing Rules
How does template type deduction differ between by-value, by-ref, and forwarding parameters? → cpp/cpp_basic: Template Type Deduction
Casting & Type Conversions#
Why prefer
static_cast,dynamic_cast,const_cast, andreinterpret_castover C-style casts? → cpp/cpp_casting: C-Style Cast (Legacy Casting)When is
dynamic_castsafe, and when does it return null or throw? → cpp/cpp_casting: dynamic_castWhat does
const_castactually guarantee, and when is it undefined? → cpp/cpp_casting: const_cast
Compile-Time Programming#
constvs.constexprvs.constevalvs.constinit— pick the right one. → cpp/cpp_constexpr: constexpr Functions · consteval · constinitHow does
if constexpreliminate branches at compile time? → cpp/cpp_constexpr: constexpr if (C++17)How has
constexprexpanded across C++14, 17, 20, and 23? → cpp/cpp_constexpr: constexpr Evolution by Standard
STL Containers & Iterators#
Compare
std::vector,std::deque, andstd::list— memory layout, iterator invalidation, complexity. → cpp/cpp_container: std::vector · std::deque · std::liststd::mapvs.std::unordered_map— trade-offs and when to use each. → cpp/cpp_container: Ordered vs Unordered ContainersWhat are the iterator invalidation rules for the common containers? → cpp/cpp_iterator: Iterator Invalidation
What are iterator categories, and why do algorithms care? → cpp/cpp_iterator: Iterator Categories
Walk through
std::sort,std::stable_sort,std::partial_sort, andstd::nth_element— when would you pick each? → cpp/cpp_algorithm: SortingDifference between
std::findandstd::binary_search? → cpp/cpp_algorithm: SearchingWhat are C++20 ranges and views? Are views lazy? → cpp/cpp_iterator: C++20 Ranges Overview
Strings#
std::stringvs.std::string_view— when isstring_viewdangerous? → cpp/cpp_string: std::string_viewWhy is naïve
+=concatenation in a loop a performance trap? → cpp/cpp_string: String Concatenation Performance
Modern C++ Features#
What does each lambda capture mode mean:
[],[=],[&],[this], init captures? → cpp/cpp_lambda: Lambda Syntax Overview · Init CaptureWhy is a captureless lambda convertible to a function pointer? → cpp/cpp_lambda: Captureless Lambdas and Function Pointers
What is a generic / template lambda? → cpp/cpp_lambda: Generic Lambdas (C++14) · Template Lambdas
What are C++20 coroutines, and what does
co_awaitactually do? → cpp/cpp_coroutine: Coroutine Basics · Promise Type · AwaiterWhy would you write a generator with coroutines instead of a class? → cpp/cpp_coroutine: Generator
What are C++20 modules, and what problem do they solve? → cpp/cpp_modules: Module Basics
autovs.decltypevs.decltype(auto)? → cpp/cpp_basic: Auto Type Deduction · decltype(auto)What does uniform / brace initialization change about narrowing conversions? → cpp/cpp_basic: Uniform Initialization
C Language Essentials#
When does an array not decay to a pointer, and what are the signed/unsigned gotchas around pointer arithmetic? → cpp/cpp_basic: Pointer Arithmetic and Negative Indices
What does
restrictpromise to the compiler? → c/c_basic: Restrict QualifierDesignated initializers and compound literals — how are they different? → c/c_basic: Designated Initializers · Compound Literals
What are flexible array members? → c/c_basic: Flexible Array Members
Why is
_Genericuseful, and how is it different from C++ overloading? → c/c_basic: _Generic Type Selection (C11)What new things did C23 bring (
nullptr,constexpr,typeof, attributes, bit-precise ints)? → c/c_basic: typeof and auto (C23) · nullptr · constexprWhy are macros dangerous, and what safer alternatives exist? → c/c_macro: Variadic Macros
Concurrency & OS#
How do you create threads in modern C++? → os/os_thread: Creating Threads
Mutex, condition variable, and read-write lock — when is each appropriate? → os/os_thread: Mutex Synchronization · Condition Variables · Read-Write Locks
std::future/std::promise/std::async— what are the launch policies? → os/os_thread: C++ Futures and Async · Launch PoliciesWhat is thread-local storage? → os/os_thread: Thread-Local Storage
Process vs. thread — what is shared and what is not? → os/os_process: Fork and Wait · Fork and Exec
Debugging & Tools#
How do you find memory leaks and invalid accesses with Valgrind? → debug/valgrind: Memcheck: Memory Errors · Leak Types
What do AddressSanitizer, ThreadSanitizer, and UBSan each catch? → debug/sanitizers: AddressSanitizer (ASan) · ThreadSanitizer · UndefinedBehaviorSanitizer
How do you inspect a core dump with gdb after a segfault? → debug/gdb: Debugging Crashes
What are breakpoints vs. watchpoints in gdb? → debug/gdb: Breakpoints · Watchpoints
Minimal modern CMake project — what are the must-have commands? → cpp/cpp_cmake: Minimal Project · Modern C++ Standard Setting
See Also#
If a question above is not covered, the top-level indices are the best next stop:
Modern C Programming — C language reference
Modern C++ Programming — Modern C++ reference
System Programming — OS and systems programming
Debugging & Profiling — Debugging and profiling tools