C++ Reference

This section documents C++23 (ISO/IEC 14882:2024), as published by ISO/IEC JTC1/SC22/WG21 (wg21), verified against the freely available working draft N5046 (eel.is/c++draft) and cppreference.com.

This content was generated with the assistance of AI and should be verified against the working draft and cppreference.com before being relied on in production.

This section’s bibliography lists the reference material consulted while preparing these pages.

Welcome to the C++ reference. C++ is a general-purpose, statically-typed, compiled language standardized by ISO/IEC JTC1/SC22 Working Group 21 (WG21) — direct control over memory and layout, plus zero-overhead abstractions (classes, templates, RAII) that cost nothing at run time compared to hand-written C. This section targets C++23 (ISO/IEC 14882:2024), flagging C++20/23-only features against their C++17 fallback wherever this environment’s own toolchain made that concrete.

If you are new here, read Getting Started and Program Structure and Compilation first, then the Language fundamentals pages in order — from there, the remaining groups (object-oriented programming, generic/compile-time programming, the standard library, error handling, concurrency, and design/performance/tooling) can be read in any order as you need them.

C and C++

C++ began in 1979 as "C with Classes" and still shares C’s declaration syntax, its arithmetic types, its pointer model, and most of its standard library (reachable through the <cXXX> headers — <cstdio>, <cstring>, <cmath>). If you already know C, most of this section will read as familiar syntax with substantially different idioms layered on top: RAII instead of manual malloc/free pairs, templates and concepts instead of _Generic and macros, std::string/std::vector instead of raw buffers and lengths, exceptions or std::expected instead of sentinel return values and errno.

C++ is not a strict superset of C, and the gap has widened rather than closed — the two are standardized by different committees (WG21 for C++, WG14 for C) that coordinate but do not merge. Valid C that is not valid C++ includes the implicit void * conversion (int *p = malloc(n); compiles in C, and needs a cast in C++), variable-length arrays, restrict, tentative definitions, and C99’s fuller form of designated initializers (C++20 accepts only the in-declaration-order subset). Meanwhile C23 has adopted several C++ spellings outright — bool/true/false as keywords, nullptr, static_assert, thread_local, [[attributes]], binary literals and ' digit separators, plus constexpr (for objects only, not functions) and auto type inference. Calling C from C++ is routine and goes through extern "C", which suppresses C++ name mangling; see Program Structure and Compilation.

The C Reference on this site documents C23 in its own right. These pages line up roughly as follows, for reading one against the other:

C page C++ page What changes

Getting Started

Getting Started

Same compilers, different -std= flag and standard library.

Program Structure

Program Structure and Compilation

C++ adds name mangling, extern "C", and modules alongside headers.

Basic Types and Values

Basic Types and Values

Shared arithmetic model; C++ adds auto/decltype, references, and stricter conversions.

Operators and Expressions

Operators and Expressions

C++ adds overloading, <⇒, and (since C++17) firmer sequencing guarantees.

Functions

Functions and Lambdas

C++ adds overloading, default arguments, lambdas, and constexpr evaluation.

Structures, Unions and Type Aliases

Classes and Objects

A C++ struct is a class with public defaults: constructors, destructors, and invariants.

Pointers

Memory Management and Smart Pointers

Raw pointers still exist; ownership moves to unique_ptr/shared_ptr and RAII.

Dynamic Memory Allocation

Memory Management and Smart Pointers

malloc/free give way to new/delete, and then to containers and smart pointers.

Arrays and Strings

Containers and Strings and Text

std::vector/std::string/std::span replace raw buffers and separate length parameters.

Type-Generic Programming

Templates and Concepts and Constraints

_Generic selection gives way to templates, overloading, and constrained generics.

Preprocessor and Macros

Namespaces, Modules, and the Preprocessor

The same preprocessor, but far less of the work falls to it.

Error Handling and Program Failure

Error Handling

Return codes and errno are joined by exceptions, RAII cleanup, and std::expected.

Input, Output and Files

Input, Output, and Streams

<cstdio> still works; iostreams, std::format and <filesystem> sit alongside it.

Threads and Atomics and Memory Consistency

Threads and Synchronization and Async, Futures, and Atomics

One shared memory model; C++ adds RAII locks, std::jthread, futures, and coroutines.

C Standards and C23

C++ Standards and C++26

Two separate release trains, deliberately kept close but never identical.

What’s Covered

Getting started

  • Getting Started — what C++ is, the standard editions, compilers, "Hello, World" with std::println, and compiling with -std=c++23 -Wall -Wextra.

  • Program Structure and Compilation — translation units, the One Definition Rule, headers, linkage, main, modules, and static vs. dynamic libraries.

Language fundamentals

Object-oriented programming

Generic and compile-time programming

Standard library

Error handling and robustness

  • Error Handling — exceptions, noexcept, error_code, std::expected, and <stacktrace>.

Concurrency

Design, performance, and tooling

Reference

  • Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.

Bibliography

Both books above are consulted references, not the primary source for this section; on any discrepancy, or wherever either is silent on a feature introduced after it was written, the working draft and cppreference.com win.