Skip to main content

Posts

C++ Smart Pointer Interview Questions

  C++ Smart Pointer Interview Questions ( unique_ptr , shared_ptr , weak_ptr ) Senior interviews on smart pointers go well beyond "what is unique_ptr ?". Interviewers want to see that you understand ownership design, control-block mechanics, thread safety, performance costs, and the classic bugs. This set of 22 questions progresses from fundamentals to implementation-level topics, each with an interview-ready answer, explanation, and example. Fundamentals 1. What problem do smart pointers solve, and how do the three types differ? Smart pointers encode ownership in the type system and use RAII to release the resource automatically, including when exceptions are thrown. They largely eliminate manual delete , leaks, and double-frees. Type Ownership Copyable? Typical cost unique_ptr Exclusive (one owner) No (move only) Same as a raw pointer (with the default deleter) shared_ptr Shared (reference counted) Yes Control block + atomic reference counting ...
Recent posts

Top 15 C++26 Features

  Top 15 C++26 Features C++26 is the first release since C++11 that changes what the language can do , not just how conveniently you write it. The ISO committee finished technical work on C++26 at its March 2026 meeting in London Croydon. The draft then moves through the ISO approval ballot and final editorial work toward publication. These are the 15 most important features, ordered by impact. The first three (reflection, contracts, std::execution ) are the headline features. Items 4 and 5 are the big safety wins. The rest are the language and library additions you are most likely to use or be asked about. A note on compiler support: implementations are still catching up, and some items below are only partially available. GCC 16 is reported to support most of the C++26 features, but check the cppreference C++26 compiler support table for the exact toolchain you ship on. The code below follows the final design, but small syntax details may differ from what your compiler accept...

Top 15 C++23 Features

  Top 15 C++23 Features C++23 is a refinement release: it finishes several things C++20 started (ranges, coroutines, modules, constexpr ) and adds a handful of long-awaited library types. These are the 15 most useful features for everyday C++, ordered roughly by how often you are likely to use them and how likely they are to come up in an interview. A note on compiler support: C++23 support varies by compiler and standard library version. Some items below ( std::generator , std::flat_map , import std; ) arrived later than others. Check the compiler support table on cppreference for the toolchain you ship on. Language Features 1. Deducing this (explicit object parameter) You can now declare the implicit this object as an explicit first parameter named this . The parameter's type is deduced just like any template argument, so a single function can handle const , non- const , lvalue and rvalue objects. Removing duplicated overloads Before, you needed up to four near-ident...

C++20 Concurrency Features for Low-Latency C++

  Important C++20 Concurrency Features for Low-Latency C++ C++20 added a useful set of concurrency primitives. For low-latency work the question is never just "does it exist?" but "what does it cost on the hot path, and does it ever block, allocate or make a syscall?" This guide covers the C++20 concurrency features that matter most, what they do under the hood, and where they help or hurt latency. A reminder of the usual low-latency rules these features are judged against: Avoid blocking on the hot path (a context switch costs microseconds, which is an eternity in this domain). Avoid hidden allocation and hidden locks. Keep shared data on separate cache lines, and minimize cache-line contention. Pin threads and create them up front. Never create threads on the hot path. Tier 1: Features You Should Know Cold 1. std::jthread and std::stop_token : safe threads and cooperative cancellation std::jthread is a std::thread that joins automatically in its de...