Tutorial

C++ Tutorial

A practical C++ tutorial for working programmers who want to get productive in modern C++. Covers tooling, memory management, OOP, modern C++ (C++11 through C++23), the STL, build systems, and best practices.

Tutorial·Difficulty: Intermediate·11 chapters·Updated May 10, 2026

Chapters

About this tutorial

A practical tour of modern C++ for programmers coming from another language. Get productive without pretending the language is small.

Who This Is For

  • Programmers fluent in another language (Python, Go, Rust, JavaScript) who need to write or read C++
  • Engineers moving into systems, games, finance, or embedded work
  • Anyone who has touched C++ before and wants the modern (C++11 to C++23) version

Contents

Fundamentals

  1. Introduction: What C++ is for, where it sits in the language landscape, and how this tutorial is shaped
  2. Tooling Setup: Compilers, the compilation model, debuggers, sanitizers, formatters
  3. Basic Syntax: Types, variables, control flow, functions, lambdas, strings, arrays

Core Concepts

  1. Memory Management: Stack and heap, pointers, references, RAII, smart pointers, move semantics
  2. Object-Oriented Programming: Classes, the rule of five, operator overloading, inheritance, polymorphism

Modern C++

  1. Modern C++: C++11 through C++23 features, ranges, concepts, coroutines, std::expected
  2. The STL: Containers, iterators, algorithms, when to reach for which container

Ecosystem

  1. Build Systems: CMake, package managers (vcpkg, Conan), warnings, sanitizers
  2. Best Practices: Memory safety, function design, common pitfalls, performance tips

Mastery

  1. Practical Projects: A task manager, a generic Vector, a thread pool, a parser, a memory pool
  2. Ecosystem Guide: Standards, terminology, compilers, libraries, community, careers

How to Use This Tutorial

  1. Read sequentially for the full path. Chapter 3 (memory) is the hinge; do not skip it.
  2. Type out the examples. C++ rewards muscle memory.
  3. Build something after each pair of chapters. Suggestions live in chapter exercises.

Quick Reference

Essential Commands

# Compile a single file with warnings on
g++ -std=c++20 -Wall -Wextra -Wpedantic file.cpp -o program

# Debug build with sanitizers
g++ -std=c++20 -Wall -g -fsanitize=address,undefined file.cpp -o program

# Release build
g++ -std=c++20 -O2 -DNDEBUG file.cpp -o program

# CMake configure and build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

# Run tests
ctest --test-dir build --output-on-failure

Hello World

#include <iostream>

int main() {
    std::cout << "Hello, C++!\n";
    return 0;
}

Common Patterns

// RAII over manual cleanup
auto buffer = std::make_unique<int[]>(1024);

// Range-based for with const reference
for (const auto& item : items) {
    process(item);
}

// std::optional for "might not exist"
std::optional<int> findIndex(std::span<const int> v, int target);

// Structured bindings
for (const auto& [key, value] : map) {
    std::cout << key << ": " << value << "\n";
}

// Move into container
container.emplace_back(std::move(value));

Learning Path Suggestions

Working Programmer (4 to 6 weeks)

  1. Chapters 0 to 2: setup and syntax (a weekend)
  2. Chapter 3: memory model. Sit with it.
  3. Chapters 4 to 6: OOP, modern features, STL
  4. Build the task manager from chapter 9
  5. Chapters 7 to 8: build systems and idioms
  6. Pick one more project from chapter 9

Reviewer or Maintainer (1 to 2 weeks)

  1. Chapter 3 (memory) and Chapter 8 (best practices). These two cover most code review failure modes.
  2. Skim Chapter 5 for which features show up in modern code.
  3. Chapter 10 for terminology and the compiler landscape.

Why C++?

  • Performance with control. You decide where allocations happen.
  • Zero-cost abstractions. High-level code compiles to tight machine code.
  • Footprint. Operating systems, browsers, databases, game engines, trading systems.
  • Longevity. The language has evolved every three years since C++11. Code from 2015 still compiles; code from 2024 looks completely different.

Additional Resources

C++ Version

This tutorial targets C++20 with notes on C++23 features. Examples compile with GCC 12+, Clang 15+, or MSVC 2022. C++17 fallbacks are mentioned where it matters.


A note on opinions: this tutorial picks a side on most contested questions (smart pointers over raw new, {} over () initialization, const references for read parameters, RAII over try/finally). The reasoning is in the prose. If you disagree, write the alternative and see how it ages.