Learn C++: Free C++ Tutorial in 131 Lessons
Learn C++ free: 131 lessons in 20 modules, from first programs to interview questions, with exercises judged on Clang 18 · C++20 and a certificate.
- Language: C++
- Runtime: Clang 18 · C++20
- Modules: 20
- Lessons: 131
- Reading time: about 35 hours
- Cost: Free on every plan, with a certificate
The language of systems, engines and the hard rounds — types and memory, RAII and ownership, classes and the rule of five, templates, the STL, concurrency and modern C++ — with exercises judged on a real C++20 compiler.
Syllabus
Module 1: C++ and the toolchain
Where C++ came from and the zero-overhead principle, the preprocess-compile-assemble-link pipeline, the anatomy of a program, the console I/O patterns every exercise uses, and how to read what the compiler says.
Module 2: Fundamental types
The built-in types and their exact sizes on this platform; integer overflow, wrap-around and bits; floating-point representation and deterministic printing; conversions and the four casts; const, constexpr and auto; literals and scoped enums.
- The fundamental types — bool, char, integers and floating point 14 min
- Integer arithmetic and bits 15 min
- Floating point — representation, error and printing 15 min
- Conversions and casts 14 min
- const, constexpr and auto 14 min
- Literals and enumerations 14 min
- Checkpoint — Fundamental types (checkpoint) 25 min
Module 3: Control flow
if/else and the conditional operator, switch with fallthrough and enums, the three loops and the unsigned countdown trap, range-based for with auto& and structured bindings, and the loop patterns every program is built from.
- Branching — if, else and the conditional operator 13 min
- switch — labels, fallthrough and what to switch on 13 min
- Loops — for, while, do…while and the traps between them 14 min
- Range-based for — iterating without indices 13 min
- Loop patterns — search, accumulate, sentinel, EOF and two pointers 14 min
- Checkpoint — Control flow (checkpoint) 25 min
Module 4: Functions
Declarations and definitions, the three ways to pass a parameter, overloading and default arguments, recursion with memoisation, a first look at lambdas, and scope, lifetime and linkage.
- Declarations and definitions — the shape of a function 12 min
- Passing parameters — by value, by reference, by const reference 14 min
- Overloading and default arguments 13 min
- Recursion — base cases, the call stack and memoisation 15 min
- Lambdas — a first look 14 min
- Scope, lifetime and linkage 14 min
- Checkpoint — Functions (checkpoint) 25 min
Module 5: Strings
std::string as a value type, the find family and slicing, characters and numeric conversions, parsing input, formatting output with iomanip and std::format, and std::string_view.
- std::string — a value type for text 13 min
- Searching and slicing 14 min
- Characters and conversions 14 min
- Parsing input 14 min
- Formatting output 14 min
- std::string_view — a window onto text 13 min
- Checkpoint — Strings (checkpoint) 25 min
Module 6: Arrays, pointers and references
Built-in arrays and std::array, pointers and nullptr, pointer arithmetic and the [begin, end) range, references and dangling, const correctness read right to left, and 2-D grids with a neighbour loop.
- Built-in arrays and std::array 14 min
- Pointers — addresses, nullptr and the arrow 14 min
- Pointer arithmetic and arrays 14 min
- References — an alias with a rulebook 14 min
- Const correctness — reading declarations right to left 13 min
- Multidimensional data — grids, layout and neighbours 15 min
- Checkpoint — Arrays, pointers and references (checkpoint) 25 min
Module 7: Memory, ownership and RAII
Storage durations and the stack-frame picture, new/delete and the ownership contract, RAII and why C++ needs no finally, std::unique_ptr and std::shared_ptr with std::weak_ptr, and the memory-error catalogue with the sanitizers that find it.
- The memory model — where objects live and when they die 14 min
- new and delete — dynamic memory and the ownership contract 14 min
- RAII — a resource's lifetime is an object's lifetime 15 min
- std::unique_ptr — exclusive ownership, enforced by the type 15 min
- std::shared_ptr and std::weak_ptr — counted ownership and its cycles 15 min
- Memory errors and the tools that find them 15 min
- Checkpoint — Memory, ownership and RAII (checkpoint) 25 min
Module 8: Classes and objects
Structs, aggregates and designated initialisers; constructors, the member-initialiser list and declaration-order initialisation; this, const member functions, mutable and chaining; static members and named constructors; invariants, friends and operator<<; the header/source split and a worked class design.
- Structs and classes — a type of your own 13 min
- Constructors — building a valid object 15 min
- this, const member functions and chaining 14 min
- Static members — state that belongs to the class 13 min
- Encapsulation and friends — the interface a class publishes 14 min
- Designing a class — headers, sources and a worked design 15 min
- Checkpoint — Classes and objects (checkpoint) 25 min
Module 9: Copies, moves and the rule of five
Copy construction versus assignment and the memberwise defaults, destructors and the rule of three, copy-and-swap, rvalue references and std::move, the moved-from state and noexcept, the generation table behind the rule of five and the rule of zero, and value categories with guaranteed elision.
- Copy semantics — what a copy is, and when the default one is wrong 14 min
- Destructors and the rule of three 14 min
- Move semantics — rvalue references, std::move and noexcept 15 min
- The rule of five and the rule of zero 14 min
- Value categories, temporaries and copy elision 15 min
- Checkpoint — Copies, moves and the rule of five (checkpoint) 28 min
Module 10: Inheritance and polymorphism
Deriving and the order of construction, virtual functions with override and final, abstract classes and interfaces held through unique_ptr, virtual destructors and slicing, the vtable, dynamic_cast and std::variant, and when composition beats inheritance.
- Inheritance basics — deriving, protected and the order of construction 14 min
- Virtual functions — static type, dynamic type and override 15 min
- Abstract classes and interfaces — programming to a contract 14 min
- Virtual destructors and slicing — the two ways a hierarchy loses data 14 min
- RTTI and the vtable — how dispatch works and when to ask an object its type 15 min
- Composition versus inheritance — is-a, has-a and the shapes to avoid 14 min
- Checkpoint — Inheritance and polymorphism (checkpoint) 25 min
Module 11: Operator overloading
Which operators to overload and where they live, the compound-first idiom, == and the C++20 spaceship with its ordering categories, << and >> that respect the stream, operator[] and operator() with functors and std::hash, and explicit on constructors and conversions.
- Overloading rules — members, free functions and the compound-first idiom 14 min
- Comparison and the spaceship operator 15 min
- Stream operators — printing and reading your own types 14 min
- Subscript, call and function objects 15 min
- Conversion operators and explicit 14 min
- Checkpoint — Operator overloading (checkpoint) 25 min
Module 12: Templates and generic programming
Function templates and deduction, Stack<T> and Pair<A, B> with CTAD, full and partial specialisation and the traits pattern, non-type parameters and fold expressions, C++20 concepts with constrained auto, and the type traits behind if constexpr dispatch.
- Function templates — one definition, every type 14 min
- Class templates — Stack<T>, Pair<A, B> and deduction 14 min
- Specialisation — when one type needs its own version 13 min
- Non-type and variadic templates — numbers and packs as parameters 14 min
- Concepts and constraints — saying what T must be 15 min
- Type traits and metaprogramming — computing with types 15 min
- Checkpoint — Templates and generic programming (checkpoint) 28 min
Module 13: STL containers
The four container families and their complexity table, std::vector's size–capacity model and the erase–remove idiom, deque, list and the adaptors, std::map and std::set with lower_bound, the unordered containers with custom hashes, and iterators with the invalidation table.
- The container zoo — choosing a container 12 min
- std::vector in depth — size, capacity and the erase–remove idiom 14 min
- deque, list and the adaptors — stack, queue and priority_queue 14 min
- std::map and std::set — the ordered containers 14 min
- The unordered containers — hashing, buckets and custom keys 13 min
- Iterators and invalidation — the contract behind every loop 14 min
- Checkpoint — STL containers (checkpoint) 25 min
Module 14: Algorithms and lambdas
The half-open range and predicate interface of <algorithm> and <numeric>, sorting with comparators and binary search, transform/accumulate/partition, lambdas as closure objects with std::function, and C++20 ranges with lazy views.
- The algorithm library — ranges, predicates and the first dozen calls 14 min
- Sorting and searching — comparators, stability and binary search 15 min
- Transforming and reducing — transform, accumulate and the erase–remove idiom 15 min
- Lambdas in depth — captures, closures, std::function and recursion 15 min
- Ranges and views — C++20 pipelines 15 min
- Checkpoint — Algorithms and lambdas (checkpoint) 25 min
Module 15: Errors and exceptions
throw, try and catch with the standard hierarchy and your own, the three exception-safety guarantees with RAII and noexcept, std::optional for absence, std::variant with std::visit for one-of-several, and error codes, assertions and a per-layer strategy.
- Exceptions — throw, try, catch and the standard hierarchy 14 min
- Exception safety — guarantees, noexcept and RAII 14 min
- std::optional — a value that may be absent 13 min
- std::variant and std::visit — a type-safe union 14 min
- Error codes, assertions and an error-handling strategy 14 min
- Checkpoint — Errors and exceptions (checkpoint) 25 min
Module 16: Modern C++
The standards from C++11 to C++23 and what compiles here; auto, decltype and structured bindings; constexpr, consteval and compile-time tables; the vocabulary types from tuple to span and chrono; concepts, ranges, <=> and std::format, with C++23 as reading.
- The standards — what each C++ added, and what runs here 12 min
- auto, decltype and structured bindings 15 min
- constexpr, consteval and compile-time tables 15 min
- The vocabulary types — pair, tuple, span, chrono and friends 15 min
- C++20 and beyond — concepts, ranges, format and what is coming 16 min
- Checkpoint — Modern C++ (checkpoint) 25 min
Module 17: Concurrency
std::thread and std::jthread with the join rule; data races and the RAII locks; atomics and compare-exchange; condition variables and a bounded queue; futures, promises and std::async; a thread pool, split-and-reduce and the deterministic-output rule for judged programs.
- Threads — std::thread, std::jthread and the join rule 14 min
- Mutexes and locks — making shared writes safe 15 min
- Atomics — lock-free counters and compare-exchange 14 min
- Condition variables — waiting without spinning 14 min
- Futures, promises and std::async — results that arrive later 15 min
- Concurrency patterns — pools, reductions and the deterministic-output rule 15 min
- Checkpoint — Concurrency (checkpoint) 25 min
Module 18: Streams and files
The stream state model and recovering from bad input, the reading-pattern catalogue with validation, file streams and open modes, string streams with std::quoted and std::format, binary records and std::filesystem.
- Streams in depth — state, recovery and the character API 15 min
- Reading structured input — the pattern catalogue 15 min
- File streams — open modes, RAII and reading back 14 min
- String streams and formatting — building text in memory 14 min
- Binary I/O and the filesystem 15 min
- Checkpoint — Streams and files (checkpoint) 25 min
Module 19: Performance and undefined behaviour
The undefined-behaviour catalogue and the well-defined detectors for it, the cost model of copies, allocations and calls, cache lines, padding and traversal order, what -O2 does under the as-if rule, and how to measure without being lied to.
- The undefined behaviour catalogue — what the compiler is allowed to assume 15 min
- The cost model — counting copies, allocations and calls 14 min
- Memory layout and the cache — contiguity, padding and traversal order 15 min
- Compiler optimisation — what -O2 does for you and what it cannot 14 min
- Measuring — clocks, benchmarks that lie and the tools that tell the truth 14 min
- Checkpoint — Performance and undefined behaviour (checkpoint) 25 min
Module 20: Interview idioms
The contest template and what it costs, the STL idiom sheet, the pitfalls that fail interviews, implementing vector and a hash map by hand, clean solutions under pressure, and the C++ theory drill.
- The interview template — the contest idioms and what they cost 13 min
- The STL idiom sheet — the two-line answers to the common shapes 14 min
- The pitfalls that fail interviews 14 min
- Implement the built-in — a vector, a unique_ptr, a hash map and a string by hand 15 min
- Writing clean solutions under time pressure 12 min
- The C++ theory drill — thirty questions, thirty answers 25 min
- Final checkpoint — Interview idioms (checkpoint) 30 min