← All articles
13 min read

C++ Interview Questions for Software Engineers (2026 Guide)

C++ interviews test very different depth depending on who is hiring. This guide groups the real questions by topic and by employer type, with model answers and the modern C++20/23 material interviewers now expect.

C++ interview questions in 2026 cluster around seven topics: memory management and RAII, move semantics, templates and constexpr, STL containers, concurrency, undefined behavior, and domain questions that depend on who is hiring. A big tech loop mostly checks that you can write correct, idiomatic C++ for algorithm problems, while HFT, game and embedded teams probe how the language maps to hardware. This guide gives you the questions, short model answers, and a map of which employer asks what.

Key Takeaways

  • Depth depends on the employer. Big tech treats C++ as a tool; trading firms, game studios and embedded teams treat it as the subject of the interview.
  • RAII and move semantics are near-universal. If you can only master two topics, master ownership and value categories.
  • Modern C++ is expected. Know C++17 cold, be fluent in core C++20 (concepts, ranges, span), and recognize C++23 features like std::expected.
  • Undefined behavior is a senior signal. Spotting signed overflow, dangling references and data races in a code snippet is a common screening question.
  • Concurrency questions go past mutexes. Low-latency roles ask about std::atomic, memory ordering and false sharing.
  • Explain cost, not just behavior. Strong answers say what the code allocates, copies and compiles to.

Which C++ Questions Does Each Employer Type Ask?

Each employer type tests a different slice of C++, so you should weight your preparation by your target. The ratings below are an editorial judgment based on what each kind of team builds, not survey data. Treat them as a starting point, not a rulebook.

TopicBig tech (Google, Meta, Microsoft)HFT / quantGamesEmbedded / automotive
Algorithms in C++Very highHighMediumMedium
RAII and smart pointersMediumHighHighHigh
Move semantics, value categoriesMediumVery highHighMedium
Templates, constexpr, conceptsLow to mediumVery highMediumMedium
STL complexity and cache behaviorMediumVery highVery highMedium
Atomics and memory orderingLowVery highMediumHigh
Undefined behaviorMediumHighHighVery high
Custom allocators, no-heap codeLowHighVery highVery high
Virtual dispatch costLowHighHighMedium

If you are aiming for a trading firm, read our breakdowns of the Hudson River Trading interview process and the Citadel interview loop, since both lean heavily on C++ internals. For general algorithm rounds, our coding interview patterns cheat sheet covers the problem types you will solve in C++.

Memory Management, RAII and Smart Pointers

RAII (Resource Acquisition Is Initialization) is the C++ idiom where an object acquires a resource in its constructor and releases it in its destructor. Because destructors run deterministically when an object leaves scope, including during stack unwinding from an exception, RAII makes leaks and double frees structurally hard.

Q: What is the difference between unique_ptr, shared_ptr and weak_ptr?

unique_ptr expresses sole ownership, cannot be copied, only moved, and has zero overhead compared to a raw pointer with the default deleter. shared_ptr expresses shared ownership through a reference-counted control block; the count updates are atomic, which costs something on every copy. weak_ptr observes a shared_ptr without keeping the object alive and is the standard fix for reference cycles.

Q: Why prefer make_shared over shared_ptr<T>(new T)?

make_shared allocates the object and control block in one allocation instead of two, which is faster and more cache friendly. The tradeoff: the memory is not released until the last weak_ptr also goes away, because the object and control block share one block.

Q: Explain the rule of zero, three and five.

If a class manages a resource directly, it needs a destructor, copy constructor and copy assignment (three), plus move constructor and move assignment (five). The rule of zero says most classes should manage nothing directly and let members like std::vector and std::unique_ptr handle it, so the compiler-generated special members are correct.

Q: Stack vs heap: when does it matter?

Stack allocation is a pointer bump and is effectively free; heap allocation goes through an allocator, may take a lock, and fragments memory. In low-latency and game code, the follow-up is usually "how would you avoid heap allocation on the hot path?" Good answers mention preallocation, object pools, arena allocators and std::pmr memory resources.

Move Semantics and Value Categories

Move semantics let an object transfer its resources to another instead of copying them. A move constructor takes an rvalue reference (T&&) and steals the source's internals, leaving the source in a valid but unspecified state.

Q: What does std::move actually do?

Nothing at runtime. std::move is a cast to an rvalue reference (an xvalue). Whether a move happens depends on whether the destination picks an overload that accepts T&&. Calling std::move on a const object silently falls back to a copy, which is a favorite trick question.

const std::string s = "hello";
std::string t = std::move(s); // copies: const string&& binds to const string&

Q: What are lvalues, prvalues and xvalues?

An lvalue has identity and cannot be moved from implicitly (a named variable). A prvalue is a pure temporary with no identity (std::string("x"), 42). An xvalue has identity but is marked as expiring, usually the result of std::move. Since C++17, prvalues initialize their destination directly, so copy elision in T x = T(); is guaranteed rather than optional.

Q: Why should a move constructor be noexcept?

std::vector uses std::move_if_noexcept when it reallocates. If your move constructor is not noexcept and the type is copyable, the vector copies every element to keep its strong exception guarantee. Forgetting noexcept can quietly turn a cheap pointer steal per element into a full deep copy per element.

Q: What is perfect forwarding?

A function template taking T&& (a forwarding reference) can pass its argument on with the original value category preserved using std::forward<T>. This is how emplace_back and make_unique construct objects in place without extra copies.

template <typename... Args>
auto make_widget(Args&&... args) {
    return std::make_unique<Widget>(std::forward<Args>(args)...);
}

Templates, constexpr and Concepts

Templates are compile-time code generators: the compiler instantiates a separate function or class for each set of template arguments. Interviewers use them to test whether you understand what happens at compile time versus runtime.

Q: What is SFINAE and what replaced it?

SFINAE (Substitution Failure Is Not An Error) means a failed template substitution removes that overload from consideration instead of causing a compile error. It powered std::enable_if tricks for years. C++20 concepts replace most of it with readable constraints and much better error messages.

template <typename T>
concept Hashable = requires(T a) {
    { std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
};

template <Hashable T>
std::size_t bucket(const T& key, std::size_t n) { return std::hash<T>{}(key) % n; }

Q: constexpr vs consteval vs constinit?

constexpr functions may run at compile time if given constant arguments, otherwise at runtime. consteval (C++20) functions must run at compile time. constinit guarantees a static variable is initialized at compile time, which avoids the static initialization order problem, but the variable can still be modified later.

Q: What is CRTP and why do trading firms like it?

The Curiously Recurring Template Pattern has a class derive from a template instantiated with itself (class Order : public Base<Order>). It gives static polymorphism: the base calls derived methods without a vtable, so calls can be inlined. HFT interviewers often ask you to rewrite a virtual interface with CRTP and explain the tradeoff in binary size and flexibility. C++23's "deducing this" (explicit object parameters) removes much of the CRTP boilerplate.

STL Containers and Complexity

Interviewers expect you to know both the Big-O and the cache behavior of each container, because the two often disagree in practice. Our Big-O notation cheat sheet covers the theory; this table adds the C++-specific details.

ContainerLookupInsert / eraseIterator invalidation on insertNotes
std::vectorO(1) indexO(1) amortized at end, O(n) middleAll, if reallocation happensContiguous, usually fastest in practice
std::dequeO(1) indexO(1) at both endsAll iterators (references stay valid at ends)Chunked storage
std::listO(n)O(1) given iteratorNonePoor cache locality
std::map / std::setO(log n)O(log n)NoneRed-black tree, ordered
std::unordered_mapO(1) averageO(1) averageAll, on rehashNode-based, pointer chasing
std::flat_map (C++23)O(log n)O(n)AllSorted vectors, cache friendly

Q: When is std::list faster than std::vector?

Rarely. Even for middle insertions, a vector often wins at moderate sizes because shifting contiguous memory is cheap compared to cache misses from following list pointers. The honest answer is "measure", with std::list reserved for cases where you need stable iterators and frequent splicing.

Q: Why might you replace std::unordered_map in a hot path?

The standard requires reference stability, which pushes implementations toward node-based buckets with a heap allocation per element. Open-addressing hash maps like Abseil's flat_hash_map store elements inline and are often faster, though you should measure. Game and trading interviewers like this question because it tests whether you know the standard's constraints.

Concurrency and Atomics

Concurrency questions in C++ interviews range from "use a mutex correctly" to "explain acquire-release ordering on ARM." For language-agnostic threading questions, see our concurrency and multithreading interview guide.

Q: What is a data race, and why is it worse in C++ than in Java?

A data race is two threads accessing the same memory location without synchronization, where at least one access is a write. In C++ a data race is undefined behavior, so the compiler may reorder or cache values in ways that break your program entirely. Java gives racy programs weaker but defined semantics.

Q: Explain memory_order_relaxed, acquire, release and seq_cst.

seq_cst (the default) gives a single global order of all sequentially consistent operations and is the easiest to reason about. release on a store and acquire on a load create a happens-before edge: everything written before the release is visible after the matching acquire. relaxed guarantees atomicity only, with no ordering, which suits counters.

std::atomic<bool> ready{false};
int payload = 0;

void producer() {
    payload = 42;
    ready.store(true, std::memory_order_release);
}

void consumer() {
    while (!ready.load(std::memory_order_acquire)) {}
    assert(payload == 42); // guaranteed by acquire-release
}

Q: What is false sharing?

False sharing happens when threads write to different variables that sit on the same cache line, typically 64 bytes on x86. The cache line bounces between cores even though no data is logically shared. The fix is padding or alignas(std::hardware_destructive_interference_size), a C++17 constant that compilers have been slow to support, so many teams hardcode 64.

Q: Design a single-producer, single-consumer queue.

This is a classic HFT question. A good answer uses a fixed-size ring buffer with power-of-two capacity, separate head and tail atomics on different cache lines, release stores and acquire loads, and no locks or allocation. Expect follow-ups on how to batch updates and why multi-producer queues are much harder.

Blanking on memory ordering mid-interview? TechScreen is a desktop AI assistant that stays invisible during screen shares on Zoom, Google Meet, Teams, HackerRank and CoderPad, and can help you structure an answer to a tough C++ question in real time. Try it with 3 free tokens, no credit card required.

Get started free →

Undefined Behavior Traps

Undefined behavior (UB) is any operation for which the C++ standard imposes no requirements. Compilers optimize on the assumption that UB never happens, so a bug can vanish in debug builds and appear at -O2. Interviewers often show a short snippet and ask "what is wrong with this?"

TrapExampleWhy it is UB or a bug
Signed overflowint x = INT_MAX; x + 1;UB; unsigned overflow wraps, signed does not
Dangling referenceReturning a reference to a localObject destroyed at end of scope
Iterator invalidationpush_back while iterating a vectorReallocation invalidates iterators
Out-of-bounds accessv[v.size()]No bounds check with operator[]
Strict aliasingReading a float through an int*Use std::bit_cast (C++20) or memcpy
Data raceUnsynchronized write from two threadsUB, not just a wrong value
Uninitialized readint x; return x;UB before C++26; "erroneous behavior" in C++26

Q: Why might this loop never terminate, or be removed entirely?

for (int i = 0; i >= 0; ++i) { /* ... */ }

Because signed overflow is UB, the compiler can assume i >= 0 is always true and turn this into an infinite loop. Mentioning -fsanitize=undefined and -fsanitize=address as the tools you use to catch these in practice is a strong signal.

Q: What does C++26 change about safety?

C++26 was technically completed at the ISO committee meeting in March 2026, according to Herb Sutter's trip report, turns reads of uninitialized variables into "erroneous behavior" with defined fallback semantics, adds a hardened standard library mode with bounds checks, and introduces contracts (preconditions, postconditions and contract_assert). It also adds static reflection and std::execution. Few companies have adopted it in production yet, so it is a talking point rather than a requirement.

Domain-Specific Questions by Employer Type

This is where C++ interviews diverge most. The same candidate can ace a Google loop and fail a trading firm screen because the second one asks what the CPU is doing.

HFT and quant firms

Trading firms such as Jane Street, HRT, Citadel Securities and Optiver care about predictable latency. Typical questions:

  • How does a virtual function call work, and what does it cost? (vtable pointer load, indirect branch, lost inlining.)
  • How would you avoid heap allocation and exceptions on the order path?
  • What is branch prediction, and how do [[likely]] and [[unlikely]] (C++20) help?
  • Implement a fixed-capacity order book level or a lock-free SPSC queue.
  • What is the difference between std::function and a template parameter for a callback, in terms of performance?

Some quant firms also mix in probability and bit manipulation puzzles. Jane Street is best known for using OCaml internally, so its interview process is less C++-heavy than HRT's.

Game studios

Game engine interviews focus on frame budgets and data layout. Expect:

  • Array of structures vs structure of arrays, and why SoA helps SIMD and cache use.
  • How would you write a pool or frame (linear) allocator?
  • Why do many engines disable exceptions and RTTI?
  • How would you design an entity component system?
  • Explain the cost of dynamic_cast.

Embedded and automotive

Embedded teams test resource limits and determinism:

  • What does volatile guarantee, and why is it not a substitute for std::atomic?
  • How do you write C++ without a heap? (Static allocation, std::array, placement new, std::span.)
  • What is the cost of templates on code size, and how do you control it?
  • Have you used MISRA C++ or AUTOSAR C++14 guidelines? MISRA C++:2023 is the current edition and targets C++17.
  • How do you handle interrupts safely with shared state?

Big tech

At Google, Meta and Microsoft, C++ is usually the language you pick for algorithm rounds, not the topic. Expect standard LeetCode-style problems where clean STL usage, correct complexity and edge cases matter more than template wizardry. Teams working on infrastructure, Chrome, Android or GPU software, such as roles covered in our NVIDIA interview guide, add language-specific rounds. If you are unsure whether to interview in C++ at all, read what language you should use in a coding interview.

Modern C++20 and C++23 Questions

Interviewers increasingly ask about features released in the last five years to check that your knowledge is current.

  • Concepts (C++20): named constraints on template parameters.
  • Ranges (C++20): composable views like std::views::filter | std::views::transform, evaluated lazily.
  • std::span (C++20): a non-owning view over contiguous memory, the modern replacement for pointer plus length.
  • Coroutines (C++20): language support for suspendable functions; C++23 adds std::generator.
  • Three-way comparison (C++20): operator<=> can generate all six comparison operators.
  • std::expected (C++23): returns either a value or an error, an alternative to exceptions popular in low-latency code.
  • std::print (C++23): type-safe formatted output built on std::format.
  • Deducing this (C++23): explicit object parameters that simplify CRTP and overloads on const and value category.

A good modern-C++ answer also says when not to use a feature. Ranges can hurt compile times, and coroutines allocate a frame unless the compiler can elide it, which matters in latency-sensitive code.

How to Prepare for a C++ Interview

Prepare in layers, starting from what every employer asks and finishing with your target domain.

  1. Week 1, core language: RAII, smart pointers, rule of five, value categories, virtual dispatch. Write a small unique_ptr and a small vector from scratch.
  2. Week 2, STL and algorithms: solve problems in idiomatic C++ and be able to state complexity and iterator invalidation rules for every container you use. Review low-level design questions, which often come in C++ for systems roles.
  3. Week 3, concurrency and UB: implement an SPSC queue, practice reading snippets for undefined behavior, and run your code under AddressSanitizer and UBSan.
  4. Week 4, domain depth: cache-aware design for trading, allocators and data layout for games, or no-heap code and MISRA for embedded.

Throughout, practice saying your reasoning out loud. C++ interviewers grade the explanation of cost and correctness as much as the code itself.

Want backup when a C++ round goes deep? TechScreen listens to the question and suggests a clear answer in real time, staying invisible to screen sharing on Zoom, Teams, Google Meet, HackerRank and CoderPad. Start with 3 free tokens, no credit card needed.

Get started free →

Frequently Asked Questions

What are the most common C++ interview questions?

The questions that come up most often are: explain RAII, compare unique_ptr, shared_ptr and weak_ptr, explain move semantics and when a move actually happens, describe how virtual functions and vtables work, explain the rule of zero/three/five, compare vector, list and unordered_map in terms of complexity and cache behavior, explain std::atomic and memory ordering, and name common sources of undefined behavior. Senior loops add templates, constexpr and concurrency design.

Which C++ standard should I know for interviews in 2026?

Know C++17 thoroughly and be comfortable with the main C++20 features: concepts, ranges, std::span, coroutines at a conceptual level, and three-way comparison. C++23 additions such as std::expected, std::print and deducing this are a plus. The ISO committee completed technical work on C++26 in March 2026, and it adds reflection and contracts, but few production codebases use it yet, so interviewers rarely expect hands-on experience.

How are HFT C++ interviews different from big tech C++ interviews?

Big tech usually treats C++ as just the language you solve algorithm problems in, so they focus on correctness and complexity. HFT and quant firms test the language and the machine itself: cache lines, false sharing, memory ordering, allocation on the hot path, branch prediction, template metaprogramming and the cost of virtual calls. Expect to explain exactly what your code compiles to and why one version is faster than another.

Is C++ a good language for coding interviews?

C++ is a strong choice if it is your daily language, because the STL is fast and interviewers at systems, games and trading firms expect it. The downside is verbosity and easy-to-make mistakes like iterator invalidation or signed overflow under time pressure. If you are equally fluent in Python, Python is often faster to write for general algorithm rounds, but for C++-specific roles you should interview in C++.

What is undefined behavior in C++ and why do interviewers ask about it?

Undefined behavior is any operation the C++ standard places no requirements on, such as signed integer overflow, reading out of bounds, dereferencing a dangling pointer, or a data race. The compiler may assume it never happens and optimize on that assumption, which can delete checks or produce results that change between builds. Interviewers ask because spotting UB separates people who write C++ that happens to work from people who write C++ that is correct.

How should I prepare for a C++ interview in a few weeks?

Spend the first week on core language: RAII, smart pointers, value categories, the rule of five and virtual dispatch. Spend the second on the STL, complexity and writing algorithm solutions in idiomatic C++. Spend the third on concurrency, atomics and undefined behavior, plus domain topics for your target employer, such as cache-friendly design for trading firms or allocators for games. Practice explaining answers out loud, not only writing code.

Ready to use AI assistance in your next interview?

TechScreen is the invisible AI assistant trusted by engineers interviewing at Google, Meta, Amazon, and hundreds of other companies. Start with 3 free tokens — no credit card required.

Ace your next interview →