C++ Interview Questions 2026
C++ interviews at systems companies (Google infra, Meta infra, gaming) go deep on memory management, undefined behavior, and performance-critical patterns.
Memory Management and RAII
RAII (Resource Acquisition Is Initialization): resources are tied to object lifetimes. Destructor runs when object goes out of scope, releasing the resource. This is the foundation of safe resource management in C++.
Smart pointers: unique_ptr for exclusive ownership (zero overhead vs raw pointer). shared_ptr for shared ownership (reference-counted, thread-safe count). weak_ptr to break cycles in shared_ptr graphs. Know when make_unique and make_shared are preferred over constructor.
Move Semantics
Move semantics avoid unnecessary copies by transferring ownership of resources. std::move casts an lvalue to an rvalue reference, enabling move constructors/assignment. After a move, the source object is in a valid but unspecified state.
Rule of five: if you define any of destructor, copy constructor, copy assignment, move constructor, or move assignment, define all five. Rule of zero: if you use only RAII wrappers, you may not need to define any.
Templates and Type Deduction
Template specialization allows different implementations for specific types. SFINAE (substitution failure is not an error) enables conditional template instantiation based on type traits. std::enable_if and if constexpr are modern alternatives.
auto type deduction: know when auto deduces a reference vs a copy. auto& for reference, const auto& for const reference. decltype for preserving exact type including references.
STL and Algorithm Complexity
Vector: O(1) amortized push_back, O(1) random access. Deque: O(1) push_front/push_back, O(1) random access but worse cache performance. Map: O(log n) all operations (red-black tree). Unordered_map: O(1) average, O(n) worst case.
Prefer STL algorithms over hand-written loops: std::sort, std::find_if, std::accumulate, std::transform. They communicate intent clearly and are often better optimized. Use range-based for loops over iterator pairs.
Browse Systems Engineering Questions
Real C++ and systems questions from infrastructure-focused roles.
Browse Google SWE Questions