C Reference

This section documents C23 (ISO/IEC 9899:2024), per ISO/IEC JTC1/SC22/WG14’s freely available working draft N3220, which WG14 documents as differing from the published standard only editorially — the reference these pages are written and verified against.

This content was generated with the assistance of AI and should be verified against the WG14 draft and cppreference.com’s C reference 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 small, statically-typed, compiled systems language: a handful of built-in types, explicit control over memory, and a thin standard library that maps closely onto what the machine and the operating system actually do. Designed by Dennis Ritchie at Bell Labs in the early 1970s to write Unix, it has been an ISO standard since 1989 and remains the language whose ABI virtually every other language uses to talk to the outside world. This section documents C23 (ISO/IEC 9899:2024), written and verified against WG14’s freely available working draft N3220, and flags C23-only features together with their C17/C11 fallbacks.

If you are new to C, read Getting Started and Program Structure first, then the Language fundamentals pages in order, followed by Pointers and memory — those two groups are what C is. From there the remaining groups (the preprocessor and generic programming, the standard library, robustness and performance, concurrency, and tooling and standards) can be read in any order as you need them. Every code example in this section compiles cleanly with clang -std=c23 -Wall -Wextra.

This site also documents C++, which began as "C with Classes" and still shares C’s declaration syntax, type model and standard library — while being neither a strict superset of C nor standardized by the same committee. Each page below links to its nearest C++ counterpart under See Also; for the relationship in one place, including a page-by-page map and the list of valid C that C++ rejects, see C and C++ on the C++ Reference landing page.

What’s covered

Getting started

  • Getting Started — what C is, the standard editions from K&R to C23, the major compilers, "Hello, World", and compiling with -std=c23 -Wall -Wextra.

  • Program Structure — declarations vs. definitions, translation units and headers, the translation phases, `main’s signatures, and exit status.

Language fundamentals

  • Lexical Structure and Style — character sets, comments, identifiers and reserved names, the C23 keyword list, every literal form, attribute syntax, and the formatting conventions.

  • Basic Types and Values — the abstract state machine, bool, character and integer types, <stdint.h> and _BitInt, floating-point types, the integer promotions and the conversion traps.

  • Constants, Enumerations and Initialization — const, enum with C23 fixed underlying types, macros vs. constexpr, compound literals, every initializer form, and static_assert.

  • Operators and Expressions — arithmetic, integer division, bitwise and shift operators, the precedence table, lvalues, and evaluation order and sequencing.

  • Control Flow — if/else, switch and fall-through, the three loop forms, break/continue, goto for cleanup, and return.

  • Functions — prototypes, pass-by-value, array parameters, recursion, static and inline, [[noreturn]], and variadic functions.

  • Arrays and Strings — array length and sizeof, multidimensional and variable-length arrays, array-to-pointer decay, string literals, and the <string.h> essentials.

  • Structures, Unions and Type Aliases — struct and designated initialization, typedef, tagged unions, bit-fields, flexible array members, and alignment and padding.

Pointers and memory

  • Pointers — address-of and dereference, pointer arithmetic, validity and dangling pointers, nullptr, void *, const and restrict, and function pointers.

  • Memory Model and Alignment — object representation, type punning, effective types and strict aliasing, and alignas/alignof.

  • Dynamic Memory Allocation — malloc/calloc/realloc/free, growable arrays, ownership rules, and the classic defects.

  • Storage Duration, Scope and Linkage — the four storage durations, the scopes, internal vs. external linkage, and thread_local.

Preprocessor and generic programming

  • Preprocessor and Macros — macro hygiene, include guards, conditional compilation, __has_include, stringification and token pasting, __VA_OPT__, and #embed.

  • Type-Generic Programming — _Generic selection, <tgmath.h>, typeof/typeof_unqual, and C23 auto.

Standard library

  • Standard Library Overview — the C23 header catalogue, the interface conventions, errno discipline, Annex K, feature-test macros, assertions, and program termination.

  • Numbers and Math — <inttypes.h> format macros, C23 checked arithmetic and bit utilities, <math.h>, <fenv.h>, <complex.h>, and pseudo-random numbers.

  • Input, Output and Files — streams and FILE, the printf and scanf families, fopen modes, fread/fwrite, positioning, buffering, and EOF vs. error.

  • Strings and Text Processing — <string.h> and <ctype.h>, numeric conversion, snprintf, locales, UTF-8, and restartable conversions.

  • Dates and Times — time_t, struct timespec, struct tm, strftime, difftime, and measuring elapsed time.

Robustness and performance

  • Error Handling and Program Failure — the catalogue of undefined behavior, state degradation, error codes, cleanup with goto, assertions, and the sanitizers.

  • Advanced Control Flow — sequencing, goto, setjmp/longjmp and volatile, and signal handlers with async-signal safety.

  • Performance — measuring first, optimization levels, inline, restrict, the C23 function attributes, profiling, and why undefined behavior is a performance feature.

Concurrency

  • Threads — <threads.h>, thrd_create/thrd_join, call_once, thread-local storage, mutexes, condition variables and the wait loop, and liveness.

  • Atomics and Memory Consistency — _Atomic types and <stdatomic.h>, compare-and-exchange, happens-before, the memory orders, fences, and false sharing.

Tooling and standards

  • Build and Tooling — compiler invocation and warning flags, Make and CMake, sanitizers and Valgrind, static analysis, clang-format, debuggers, and Doxygen.

  • Testing — assert-based checks, a minimal harness, Unity / CMocka / Check / Criterion, CTest, and testing UB-sensitive code under sanitizers.

  • C Standards and C23 — the editions timeline, what C23 added and removed, the compiler support matrix, and writing transitional code.

Reference

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

Bibliography

The book above is a consulted reference, not the primary source for this section; on any discrepancy, or wherever it is silent on a feature introduced after it was written, the official ISO/IEC 9899:2024 standard and its N3220 working draft win.