Visual primers for ideas you hit every day with g16. Reference-first, with textbook diagrams. Compile examples with g16 -std=gnu17 (C) or g16 -std=gnu++26 (C++).
A pointer holds an address. *p reads the value at that address; &x takes the address of x.
p stores the address of x; dereferencing reads 42.int x = 42;
int *p = &x;
printf("%d\n", *p); /* 42 */
*p = 7; /* x is now 7 */
C++ adds nullptr, references int& r = x, and smart pointers (std::unique_ptr) for RAII.
Arrays are a fixed-length contiguous block. Index i lands at base + i * sizeof(T). In C, array names decay to a pointer to the first element.
int a[5] — five elements in one contiguous slab; cache-friendly iteration.C++ prefer std::array<T,N> or std::vector<T> with bounds-aware interfaces; Field code often uses stack arrays in hot paths.
| API | Typical complexity | Notes |
|---|---|---|
qsort (C) | O(n log n) avg | Function pointer comparator; not type-safe |
std::sort | O(n log n) | Introsort; mutates range; random-access iterators |
std::stable_sort | O(n log n) | Preserves order of equal elements |
Automatic storage: locals, small fixed arrays. Freed on scope exit. Fast, LIFO, limited size.
malloc / new — explicit lifetime. Larger, flexible. Pair with free / delete or smart pointers.
Compile-time generics: one definition, many types. Instantiations happen at compile time — zero runtime polymorphism cost when inlined.
template <typename T>
T add(T a, T b) { return a + b; }
Resource Acquisition Is Initialization — bind resource lifetime to object lifetime. Destructor releases handles, locks, memory. Core to modern C++ and Grok16 field mandates (no leaks in L2).
Rvalue references (T&&) and std::move transfer ownership without copying heavy buffers — critical for FieldX86 vectors and matrix paths under -O3.