C++ Demo Examples

Scope: Larger, self-contained practice programs — one file each. Every demo is fully commented so you can read why, not only what: open it in the code viewer, download it, build it, and change it.

These demos go beyond the one-liners in the lessons — each combines several ideas into one working program you can break and fix. Only the standard library is used, so nothing extra needs installing. Build with any C++17 compiler:

# GCC or Clang
g++ -std=c++17 -Wall -Wextra 01_types_and_operators.cpp -o demo01 && ./demo01

# the concurrency demos (11, 12) need the threading library
g++ -std=c++17 -Wall -Wextra -pthread 11_threads_mutex.cpp -o demo11 && ./demo11

# on Windows with MSVC
cl /std:c++17 /EHsc 01_types_and_operators.cpp

Foundations

Types, operators and control flow — the primitives every other demo builds on.

#DescriptionLink
1Types, Size and OperatorsView
2Control Flow PatternsView

Functions & References

Parameter passing, overloading, and the practical difference between references and pointers.

#DescriptionLink
3Functions, Overloads & DefaultsView
4References & PointersView

Objects & RAII

Classes that enforce an invariant, and RAII — the pattern that makes C++ cleanup automatic.

#DescriptionLink
5Classes, Invariants & RAIIView
6Inheritance & PolymorphismView

Containers & Algorithms

Choose the right STL container, then let algorithms and lambdas replace hand-written loops.

#DescriptionLink
7Containers: vector, map, setView
8Algorithms & LambdasView

Modern C++

Move semantics and templates — the features that make modern C++ fast and generic.

#DescriptionLink
9Move Semantics (copy vs move)View
10Templates & GenericsView

Concurrency

Threads, data races, mutexes, atomics and task-based parallelism.

#DescriptionLink
11Threads & Mutex (data races)View
12async, future & atomicView

Enterprise Patterns

Production building blocks: structured logging with RAII, and the Observer pattern.

#DescriptionLink
13Logging & RAII Timing GuardView
14Observer / Event BusView