Languages

C++ Mastery

Memory, pointers, templates, the STL and modern C++ explained with small examples.

  • Handwritten-style
  • Diagrams and tables
  • Worked examples

Who this notebook is for

Students and developers preparing for C++ interviews, and anyone who finds pointers, references and templates confusing. It explains each idea with a small picture first.

What you will be able to do

  • Explain stack, heap, pointers and references with a memory diagram
  • Use smart pointers and RAII to avoid leaks
  • Write and read simple templates and use the STL containers and algorithms
  • Describe move semantics and when the compiler uses them

What's inside

Pick a chapter and the notebook opens right there.

  1. Compilation Model & Memory Architecture4-Stage Toolchain, One Definition Rule (ODR), Virtual Memory Layout, Stack vs Heap, Storage DurationStart here
  2. Modern Types, Values & InitializationUniform {} Init, Narrowing Prevention, auto & decltype(auto), Value Categories (prvalue, xvalue, lvalue), constexpr & constevalStart here
  3. Pointers, References & Object LifetimesRaw Pointers, Pointer Arithmetic, Lvalue vs Rvalue References, Dangling References, Const Correctness & mutableStart here
  4. RAII & Smart Pointer ArchitectureResource Acquisition Is Initialization, std::unique_ptr, std::shared_ptr Control Block, std::weak_ptr Cycles, Custom DeletersStart here
  5. Move Semantics & Perfect ForwardingRule of 0/3/5, std::move Invariants, Universal References, Reference Collapsing, std::forward, RVO/NRVO Copy ElisionStart here
  6. Classes, OOP & Polymorphism Under the HoodVtable Pointer Layout, Dynamic Dispatch Overhead, Virtual Destructors, Abstract Interfaces, Multiple & Diamond InheritanceStart here
  7. Operator Overloading & Custom TypesSemantic Invariants, Hidden Friends, Stream I/O (<<, >>), C++20 Spaceship Operator (<=>), UDLs, Explicit ConversionsStart here
  8. Dynamic Memory & Custom Allocatorsoperator new/delete, Placement New, Custom Arena Bump Allocators, Struct Alignment & Padding, std::pmr (C++17)Start here
  9. Templates & Generic ProgrammingMonomorphization, NTTP, Full vs Partial Specialization, Two-Phase Name Lookup, Variadic Packs, Fold ExpressionsStart here
  10. Compile-Time Metaprogramming & ConceptsTuring-Complete TMP, Type Traits Library, SFINAE & void_t, if constexpr, C++20 Concepts & Subsumption RulesStart here
  11. STL Containers: Sequences & Adaptorsvector Geometric Growth, array & deque Chunked Pages, list Cache Miss Penalties, Adaptors, Invalidation RulesStart here
  12. STL Associative & Unordered ContainersRed-Black Tree Invariants, Hash Table Chaining & Rehashing, Custom Hasher & Equality, C++23 Flat ContainersStart here
  13. STL Algorithms, Iterators & RangesIterator Categories, No Raw Loops, Introsort & Quickselect, C++20 Ranges & Views Pipe (|), Parallel PoliciesStart here
  14. Exceptions & Modern Error HandlingZero-Cost Itanium ABI, Stack Unwinding, Exception Safety Guarantees, noexcept Optimizations, std::expected (C++23)Start here
  15. Concurrency & C++ Memory Modelstd::jthread & stop_token, std::scoped_lock Deadlock Avoidance, Condition Variables, std::atomic & Memory Ordering, Lock-Free SPSCStart here
  16. Modern C++ Standards (17 / 20 / 23)Structured Bindings, C++20 Modules (10x Build Acceleration), Coroutines (co_await), std::span & string_view, std::format, SSOStart here
  17. Performance, Profiling & Systems C++CPU L1/L2/L3 Latencies, Branch Prediction [[likely]], SoA vs AoS SIMD, Compiler Inlining/RVO, Sanitizers (ASan/TSan), UB TrapsStart here
  18. Top 30 FAANG Technical Interview DrillsDrills 1–30: Object Slicing, Move Traps, Lock-Free Ring Buffer, High-Throughput Object Pool & Principal Engineer ChecklistStart here

Practice this

Put it to work on LakeBench.

Common questions

Do I need to know C before this notebook?
No. It starts from how a C++ program is compiled and how memory is laid out, then adds one feature at a time.
Does it use modern C++?
Yes. It covers move semantics, smart pointers, concepts and ranges as well as the older features.
Can I read a sample before I commit?
Yes. The contents pages and the first pages of every notebook can be read online, so you can judge the style before going further.

More in Languages

All notebooks