P
prepair.app
Start interview →
EnglishУкраїнськаРусский
🔷

Senior C++C++ interview questions

Senior · 5+ years of experience

C++ interviews test three things: whether you understand the object model, whether you can be trusted with memory, and whether you know what the standard library costs. Below are the questions asked most often, each with a model answer. Senior: architecture, trade-offs, mentoring, and decision-making.

Topics to prepare

Memory, pointers and RAII
OOP, virtual functions and vtable
Move semantics and the rule of five
Templates and metaprogramming
STL containers and complexity
Concurrency and data races

5 Senior-level questions with answers

1

How do cache misses shape the way you lay out data?

Answer

A miss to main memory costs on the order of a couple of hundred cycles, so a structure that is theoretically better can lose badly to a contiguous array. That leads to laying data out the way it will be traversed — structure-of-arrays when you touch one field over many objects, packing hot fields together, and avoiding pointer chasing in the inner loop. False sharing is the same problem inverted: two threads writing to different variables in one cache line serialise on it, and the fix is padding to a cache line.

2

When is lock-free worth it, and what is the difference from wait-free?

Answer

Lock-free guarantees that some thread makes progress; wait-free guarantees every thread makes progress in a bounded number of steps. Lock-free is worth it under real contention on a small, well-understood structure — a queue, a counter — where a mutex measurably dominates. It is not worth it as a default: the code is hard to write correctly, hard to test, and a well-used mutex is fast in the uncontended case, so the honest answer usually starts with a measurement.

3

Explain memory ordering in `std::atomic`.

Answer

seq_cst is the default and gives a single total order across all threads — correct, and the easiest to reason about. acquire/release pairs establish a happens-before between the releasing store and the acquiring load, which is what a lock does internally and is enough for most producer-consumer patterns. relaxed guarantees only atomicity, no ordering, and is appropriate for things like a statistics counter. Weakening the ordering is a measured optimisation, not a starting point.

4

A project takes twenty minutes to build. How do you attack it?

Answer

Measure first — which translation units and which headers dominate. Then cut the header graph: forward declarations instead of includes, PIMPL on the widely included classes, and moving templates out of headers where instantiation cost is real. After that come the mechanical wins — precompiled headers, ccache, parallelism, unity builds, and a linker like lld or mold. Modules solve it properly where the toolchain is ready for them.

5

Code is slower than it should be. What is your method?

Answer

Start from a reproducible measurement, because intuition about C++ performance is wrong often enough to be dangerous. Profile to find where the time actually goes, then look at the algorithm before the micro-optimisations. Check what the optimiser did rather than assume — the generated code answers questions that reading the source cannot. And control the environment: build flags, warm caches, frequency scaling and noise from other processes will otherwise produce numbers that are not real.

🦎

Reading answers is not enough

In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.

Practice a Senior C++ interview →
Free · 3 interviews per month

Other levels — C++

Junior C++Middle C++All C++ questions

Other specializations

🔍Senior Manual QA🤖Senior QA AutomationSenior Java Backend🐍Senior Python Backend🐘Senior PHP Backend🦫Senior Go Backend🟢Senior Node.js Backend💎Senior Ruby on Rails🟨Senior JavaScript⚛️Senior React Frontend