Book Exercise Lanes
This module's exercise system is book-driven. Use these local chunks for targeted volume after you have already learned the concept from the guide.
How To Use This Page
- Finish the relevant concept page first.
- Solve at least one problem of your own from memory.
- Only then open the matching exercise lane.
- Keep a mistake log with tags such as
off-by-one on buffer,signed overflow is UB,dangling after realloc,wrong byte order on wire,missing trailing NUL,unaligned access, orsizeof does not sum fields.
Lane 1: Representation (Bits, Integers, Floats)
Use this lane when the issue is reading or manipulating bit patterns.
- K&R: Bitwise Operators
- CODE: Bit by Bit by Bit
- CODE: Bit by Bit by Bit (Part 2)
- CODE: Bytes and Hexadecimal
- CODE: But What About Subtraction
- CODE: But What About Subtraction (Part 2)
- COD: Signed and Unsigned Numbers
- COD: Signed and Unsigned Numbers (Part 2)
- COD: Floating Point
- COD: Floating Point (Part 2)
Target outcomes:
- 10 hex/binary/decimal conversions, including negative values in two's complement
- 6 exercises on
&,|,^,~,<<,>>(set, clear, toggle, extract, count bits) - 4 IEEE 754 encode/decode exercises by hand
- 2 written explanations of signed-vs-unsigned surprises (comparison, conversion)
Lane 2: Pointers, Arrays, Function Pointers
Use this lane when pointer code "kind of runs" but you cannot draw the diagram.
- K&R: Pointers and Addresses
- K&R: Pointers and Function Arguments
- K&R: Pointers and Arrays
- K&R: Address Arithmetic
- K&R: Character Pointers and Functions
- K&R: Pointer Arrays, Pointers to Pointers
- K&R: Multi-Dimensional Arrays
- K&R: Command-Line Arguments
- K&R: Pointers to Functions
- K&R: Complicated Declarations
Target outcomes:
- 10 programs or diagrams translating pointer code into a memory picture before running
- 6 exercises implementing
strlen-style functions using pure pointer arithmetic - 4 function-pointer exercises including a dispatch table and a
qsortcomparator - 2 written analyses of
int *a[n]versusint (*a)[n]
Lane 3: Memory Layout and Allocation
Use this lane when you can manipulate pointers but cannot account for where memory comes from or goes.
- K&R: Basics of Structures
- K&R: Structures and Functions
- K&R: Self-Referential Structures
- K&R: Example - A Storage Allocator
- COD: Supporting Procedures in Computer Hardware
- COD: Supporting Procedures (Part 2)
- COD: Supporting Procedures (Part 3)
- COD: Translating and Starting a Program (Part 5)
- CODE: An Assemblage of Memory (Part 2)
Target outcomes:
- 4 exercises placing each variable in a small program into its correct segment
- 3 stack-frame traces on paper (simple, recursive, with spilled locals)
- 2 toy allocators: one bump, one single free-list
- 2
reallocexercises including "what if it moves?" handling
Lane 4: Memory Errors, Tools, and Hardening
Use this lane when the theory is clear but you need fluency with the tools and idioms.
- Clang AddressSanitizer
- Clang UBSan
- Valgrind Memcheck manual
- Clang Static Analyzer
- GCC
-fanalyzer - CWE-121, CWE-415, CWE-416, CWE-787
Target outcomes:
- 3 buggy programs run through ASan and fixed
- 2 buggy programs run through Valgrind Memcheck and fixed
- 1 program run through
clang --analyzeor-fanalyzerand fixed - 1 written narrative explaining how a tool located a bug you could not find by reading
Lane 5: Structs, Alignment, Endianness, Bit Fields
Use this lane when your layout predictions are off or when you need to write wire formats.
- K&R: Basics of Structures
- K&R: Arrays of Structures
- K&R: Pointers to Structures
- K&R: typedef
- K&R: Unions
- K&R: Bit Fields
- The Lost Art of Structure Packing (Raymond)
- Bit Twiddling Hacks (Anderson)
Target outcomes:
- 5
sizeofandoffsetofpredictions across 5 different struct orderings - 3 reorderings that reduce size, each with a
_Static_assertfreezing the layout - 2 wire-format exercises writing explicit big-endian encode/decode (no
htonl) - 1 bit-field / packed-struct exercise parsing a real protocol header (UDP, Ethernet, or a custom format)
Self-Curated Problem Set
Build a custom set with these minimums:
- 5 bit-pattern and arithmetic problems
- 5 pointer-and-arithmetic prediction problems
- 5 memory-layout or allocator problems
- 5 memory-error diagnosis problems using ASan / Valgrind
- 3 struct / endianness wire-format problems
Completion Checklist
- Completed at least one lane in full
- Logged at least 12 real mistakes and corrections in the mistake log
- Drew at least 10 memory diagrams before writing the corresponding code
- Fixed at least 3 bugs that ASan or Valgrind located
- Wrote at least 3 wire-format encode/decode exercises that round-trip across simulated endianness