Companion code

Every listing, ready to build

166 files across 15 chapters. Each one was compiled with the book's flags and behaves as the text says.

Download everything (104 KB) Set up your workbench first

Build C files with the book's standard line, and C++ files from Chapter 12 on with its C++ twin:

gcc -std=c17 -Wall -Wextra -Werror -g -fsanitize=address,undefined prog.c -o prog
g++ -std=c++20 -Wall -Wextra -Werror -g -fsanitize=address,undefined prog.cpp -o prog

Some files are wrong on purpose: an agent draft with planted defects, a leaky version to run under Valgrind, a race for ThreadSanitizer to find. The chapter says which, and what the instrument should report. Predict before you run.

ChapterFiles
ch03 Control Flow, Functions, Recursion, and Counting Operations3ch03.zip
ch05 Arrays, Strings, and Matrices: n, n², n³6ch05.zip
ch06 The Stack and the Heap: Dynamic Memory and Ownership5ch06.zip
ch07 Structs, Headers, and Multi-File Programs8ch07.zip
ch08 Growable Arrays and Linked Lists: The Cost of Growth3ch08.zip
ch09 Files, Bits, and Function Pointers: ADTs Behind a Header24ch09.zip
ch10 Complexity and Sorting: Your First Delegation15ch10.zip
ch11 Specify First: Abstract Data Types15ch11.zip
ch12 Moving to C++: Is It Really C++?14ch12.zip
ch14 Resource Ownership: RAII, the Rules of Zero, Three, and Five, and Smart Pointers10ch14.zip
ch15 Inheritance, Polymorphism, and Composition: Reviewing an Agent's Design11ch15.zip
ch16 Templates and the Standard Library7ch16.zip
ch17 Binary Search Trees16ch17.zip
ch18 Hash Tables, Exceptions, and the Search Study12ch18.zip
ch20 A First Look at Concurrency17ch20.zip

Chapters 1, 2, 4, 13 and 19 work from listings in the text and the files of the chapters around them, so they have no folder of their own.