# C Language Reference
## Languages — The Codex Coding
**URL:** https://thecodex.expert/coding/languages/c/
**Type:** language-reference | **Confidence:** high | **Last verified:** 2026-06-01

## CANONICAL DEFINITION
C is a general-purpose, procedural, statically typed, compiled programming language that compiles to native machine code, provides manual memory management via malloc/free, direct memory access through pointers, and no runtime overhead — the foundational systems programming language of operating systems, kernels, compilers, and embedded systems.

## QUICK FACTS
- **Created:** 1969–1973 by Dennis Ritchie at Bell Labs
- **Standard:** C17 (ISO/IEC 9899:2018) | C23 published 2024
- **Typing:** Static, weak — type sizes are platform-defined
- **Execution:** Native compiled (no VM, no interpreter, no runtime)
- **Memory:** Manual — malloc/free; no garbage collector
- **Paradigm:** Procedural

## CRITICAL NOTES
- **Undefined behaviour (UB):** signed int overflow, null dereference, OOB access, use-after-free are ALL UB — compilers may optimise them away producing security holes. Use -fsanitize=address,undefined during development.
- **Arrays decay to pointers:** passing an array to a function loses its size. sizeof(arr) gives bytes only in declaring scope. Always pass length separately.
- **No string type:** strings are null-terminated char arrays. Buffer overflows are the most common C vulnerability. Use snprintf/strncpy not sprintf/strcpy.
- **C ≠ C++:** different languages. Not all C is valid C++. Linux kernel is strict C.
- **Type sizes are platform-defined:** use <stdint.h> (int32_t, int64_t, etc.) for portability.
- **Signed integer overflow is UB** (not wrap-around). Unsigned overflow wraps modulo 2^n (defined).

## MEMORY SEGMENTS
- text: executable code (read-only)
- data: initialised global/static variables
- BSS: uninitialised global/static (zero-initialised by OS)
- stack: local variables + call frames (grows down)
- heap: malloc/free (grows up)

## STANDARD VERSIONS
- C89/C90: original ANSI C
- C99: inline, mixed declarations, VLAs, stdint.h, stdbool.h, //comments
- C11: _Generic, _Static_assert, stdatomic.h, threads.h
- C17: defect fixes only
- C23: nullptr, 0b binary literals, #embed, typeof, constexpr

## COMPILERS AND TOOLS
- GCC (gcc.gnu.org): most widely deployed
- Clang (clang.llvm.org): better diagnostics, -fsanitize support
- Valgrind: runtime memory error detection
- AddressSanitizer (-fsanitize=address): heap/stack overflow detection
- UBSan (-fsanitize=undefined): undefined behaviour detection

## SOURCES
- ISO C17: iso.org/standard/74528.html
- K&R: Kernighan & Ritchie, The C Programming Language (2nd ed., 1988)
- Secure Coding in C and C++ (Seacord, 2013)

*The Codex Coding — thecodex.expert/coding/ — Free forever — Mumbai, India*
