Skip to content

C Practice

Master manual memory management, pointer arithmetic, and undefined behavior avoidance.

ConceptDetails
Memory ModelManual allocation (malloc/free), stack vs heap, no GC
Type SystemWeak static typing, implicit conversions, void* generics
Error HandlingReturn codes, errno, setjmp/longjmp (avoid)
Concurrencypthreads, atomics (stdatomic.h), no language-level async
Buildgcc/clang, make, cmake, header/source separation
StandardC11 (prefer) or C17
  • Opaque pointers for encapsulation (struct Foo; in header, definition in .c)
  • Goto cleanup pattern for resource management
  • Flexible array members for variable-length structs
  • Static inline functions in headers for zero-cost abstractions
  • Compound literals for temporary struct values
  • Designated initializers for readable struct initialization
Terminal window
practice/bin/ol list build c # which of these have references yet
practice/bin/ol start build c 01 # clone it stubbed into .scratchpad/
practice/bin/ol check build c 01 # run it; exit code is the verdict
practice/bin/ol diff build c 01 # your attempt against the reference

Exercises are ordered by concept, not by difficulty, so pick by the stars rather than by the number. An exercise listed below with no reference yet is a row in this table and nothing more; see the practice path for how the harness works.

Implement each using only the C standard library. No external dependencies.

#ExerciseConceptsDifficulty
01Dynamic array (vec.h)realloc, growth factor, generics via macros; course version: ds.01, lang.03⭐⭐
02Hash map (open addressing)Hash functions, probing, load factor; course version: ds.02 (this drill is its worked baseline)⭐⭐⭐
03Linked list (intrusive)Container-of macro, pointer manipulation; course version: ds.03⭐⭐
04Binary heapArray-based, sift_up/sift_down; course version: ds.04⭐⭐
05Merge sort (in-place)Pointer arithmetic, recursion⭐⭐
06Graph (adjacency list)Flexible arrays, BFS/DFS⭐⭐⭐
07Thread poolpthreads, condition variables, work queue; course version: rt.03⭐⭐⭐⭐
08Arena allocatorMemory management, alignment, bump allocation; course version: rt.02⭐⭐⭐
09String interningHash table, strdup, lifetime management⭐⭐⭐
10Simple HTTP parserState machine, buffer management, recv⭐⭐⭐⭐