Appendices: Projects, Review Questions, Cheat Sheet & Resources
Capstone projects, interview and review questions, a cheat sheet, Zig for C / Rust / Go / C++ developers, and resources.
Appendix A: Capstone Projects
Beginner: CLI Utilities. Reimplement wc, cat, grep (basic), and head with arg parsing, buffered I/O, error handling, and tests.
Beginner: Text Adventure / To-Do App. Tagged unions for commands, StringHashMap, JSON persistence via std.json.
Intermediate: Tokenizer + Recursive-Descent Calculator. Lexer with a labeled switch, tagged-union AST in an arena, REPL, fuzz tests.
Intermediate: Key-Value Store Server. TCP server (std.net) with thread-per-connection or a thread pool, RESP-like protocol, append-only log persistence, an integration test client.
Intermediate: Generic Data Structures Library. RingBuffer(T), LruCache(K, V), BTree(K, V) with comptime generics, full tests using testing.allocator and checkAllAllocationFailures. Publish as a package.
Advanced: Bytecode Interpreter / Mini Language VM. Compiler to bytecode, a stack VM using continue :dispatch labeled switch dispatch, GC or arena memory, benchmarks.
Advanced: Comptime Serializer. Reflection-based binary or MessagePack serializer for arbitrary structs, unions, and slices, with custom-method hooks.
Advanced: C Library Port / Binding. Package a C library (e.g., zlib, libpng, SQLite) with build.zig, write idiomatic Zig wrappers, and cross-compile for 3 OSes.
Advanced: HTTP API Service. http.zig + pg.zig/zqlite, JSON endpoints, middleware, logging, configuration via ZON, Docker image built from scratch with a static musl binary.
Systems: Bare-Metal Firmware or Toy Kernel. MicroZig blinky + UART + timers on an RP2040, or an x86_64 kernel with Limine, a serial console writer, a page-frame allocator, and interrupts.
Graphics: 2D Game. raylib-zig or Mach, an ECS with MultiArrayList, fixed-timestep loop, WASM build for the browser.
Performance: Data-Oriented Particle Simulator. AoS vs SoA vs SIMD comparison, multi-threaded with Thread.Pool, profiled with Tracy/perf.
Appendix B: Interview and Review Questions
What does "no hidden control flow" and "no hidden allocations" mean in Zig?
Difference between const and var? Why must runtime vars have explicit types for literals?
What is undefined, and what happens in Debug mode?
What are comptime_int and arbitrary-width integers like u3?
Wrapping (+%) vs saturating (+|) vs normal arithmetic: what does each do on overflow per build mode?
Explain @intCast, @truncate, @bitCast, and @as.
How do labeled blocks and labeled loops work?
How do for loops with ranges, indices, and multiple objects work?
Why are unused variables errors? How do you discard values?
Why doesn't Zig have operator overloading, exceptions, or default arguments?
Types and Memory Arrays vs slices vs many-item pointers vs array pointers?
What are sentinel-terminated types ([:0]u8, [*:0]u8)?
How are strings represented? How do you compare them?
Explain auto, extern, and packed structs.
What is a tagged union? How does inline else help?
How do optionals work (?T, orelse, .?, capture)?
Error sets vs error unions vs anyerror. How do try and catch work?
What are error return traces?
defer vs errdefer: give a resource-cleanup example.
Why does Zig pass allocators explicitly? Name the standard allocators and their use cases.
How does ArenaAllocator simplify memory management?
How do you detect leaks in tests?
What changed with ArrayList in 0.15 (managed vs unmanaged)?
What is comptime? What can and can't run at compile time?
How do generic types work (fn List(comptime T: type) type)?
What does anytype do, and what are its trade-offs?
How do you use @typeInfo, @field, and @Type for reflection?
Describe three ways to implement polymorphism/interfaces in Zig.
How does std.mem.Allocator's vtable interface work?
What is @fieldParentPtr used for?
Explain the four build modes and the safety checks in each.
How do @setRuntimeSafety and @branchHint work?
How do you call C from Zig and Zig from C? What is translate-c?
Why is zig cc useful even for non-Zig projects?
How does cross-compilation work, including libc?
Explain build.zig: modules, artifacts, steps, options, dependencies.
What is build.zig.zon? How are dependencies fetched and verified?
What happened to async/await, and what is the std.Io plan?
What is "Writergate" (0.15 I/O changes) and how do you write to stdout now?
How do threads, mutexes, and atomics work in Zig?
What is data-oriented design, and how does MultiArrayList support it?
How do you write freestanding/embedded code (panic handler, linker script, volatile MMIO)?
Implement fn Stack(comptime T: type) type with push, pop, peek, and deinit (unmanaged style).
Write a function that reverses words in a string in place.
Implement a tokenizer for arithmetic expressions using a labeled switch.
Write a generic fn maxField(comptime field: []const u8, items: anytype) using @field.
Implement a thread-safe bounded queue with Mutex + Condition.
Write a custom allocator that counts allocations and bytes.
Call qsort from libc with a Zig comparator.
Parse a JSON config into a struct with default values.
Appendix C: Zig Cheat Sheet
const std = @import("std");
// ===== Variables =====
const a = 5; // comptime_int constant
var b: u32 = 10; // runtime mutable
var buf: [64]u8 = undefined;
const x, const y = .{ 1, 2 }; // destructuring
// ===== Control flow =====
if (b > 5) {} else {}
const m = if (b > 5) "big" else "small";
while (b < 20) : (b += 1) {}
for (items, 0..) |item, i| {}
for (0..10) |i| {}
const s = switch (b) { 0 => "zero", 1...9 => "digit", else => "big" };
const v = blk: { break :blk 42; };
// ===== Functions =====
fn add(p: i32, q: i32) i32 { return p + q; }
fn mayFail() !u32 { return error.Oops; }
fn generic(comptime T: type, val: T) T { return val; }
fn mutate(ptr: *u32) void { ptr.* += 1; }
// ===== Errors & optionals =====
const r = try mayFail();
const r2 = mayFail() catch 0;
const opt: ?u32 = null;
const o = opt orelse 7;
if (opt) |val| {}
errdefer cleanup();
defer file.close();
// ===== Types =====
const P = struct { x: f32 = 0, pub fn len(self: P) f32 { return self.x; } };
const E = enum { a, b };
const U = union(enum) { int: i64, text: []const u8 };
const Flags = packed struct(u8) { r: bool, w: bool, _: u6 = 0 };
fn List(comptime T: type) t
…zig run f.zig | zig test f.zig | zig build | zig build run | zig build test
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-windows
zig init | zig fmt . | zig fetch --save <url> | zig cc | zig translate-c h.hAppendix D: Zig for C / Rust / Go / C++ Developers
macros / void* generics + traits comptime params Result<T, E> E!T + try/catch defer / errdefer new/delete, smart ptrs build.zig.zon (URLs) vtables, tagged unions, anytype Key gotchas:
C devs: there's no implicit integer conversion or narrowing, strings are slices (not null-terminated by default), and you must handle every error.
Rust devs: there's no borrow checker (memory safety comes from runtime checks plus discipline), and comptime replaces traits and macros.
Go devs: there's no GC. Allocators are explicit, and defer is block-scoped, not function-scoped.
C++ devs: there are no constructors/destructors (RAII), no overloading, no exceptions, and no templates. Use comptime functions returning types.
Appendix E: Resources
ziglang.org: Downloads, Language Reference (the single-page "langref"), Standard Library docs (zig std), release notes (essential reading for each version), the "Learn" section
Zig Software Foundation: ziglang.org/zsf Source: codeberg.org/ziglang/zig (development moved from GitHub in 2025)
Ziglings (exercises: fix small broken programs), zig.guide, *Introduction to Zig* by Pedro Duarte Faria (free online book), Zig by Example, Karl Seguin's "Learning Zig" series (openmymind.net), Exercism Zig track
Talks: Andrew Kelley's "The Road to Zig 1.0" and "Practical Data-Oriented Design", Loris Cro's talks on async/Io and the build system, Zig SHOWTIME videos
Codebases to read: the Zig standard library (lib/std), TigerBeetle (the TIGER_STYLE guide), Bun, Ghostty, http.zig, Mach, zig-gamedev, MicroZig
ziggit.dev (forum), the Zig Discord, r/Zig, zigistry.dev and awesome-zig (package discovery), the allyourcodebase org, Zig News (zig.news) Suggested 12-Week Study Plan
Setup, syntax, variables, types (plus Ziglings 1–30) Operators, casting, control flow, functions Arrays, slices, pointers, strings Structs, enums, unions, optionals Errors, defer, allocators, containers I/O interfaces, files, modules, testing
Comptime, generics, reflection, interfaces Builtins, safety and build modes, low-level layout, SIMD/asm Threads, async/Io, C interop, zig cc
Build system, packages, cross-compilation, JSON, networking, CLI
Embedded, OS dev, WASM, games (pick one or two) 46–49 + Capstone
Debugging, performance/DoD, idioms, internals Final tip: Do Ziglings alongside this course, keep the Language Reference open, read the release notes before upgrading, and read the standard library source: it's the best example of idiomatic Zig. Build things, break things in Debug mode, and let the safety checks teach you. Happy hacking! ⚡