A hands-on introduction to Zig via annotated examples. Zig is a general-purpose, compiled systems language focused on robustness, optimality, and simplicity — no hidden control flow, no hidden allocations, no preprocessor.
Written by Dariush Abbasi for Boring College
content/NN-name.md— the annotated chapterexamples/NN-name.zig— the runnable source
Every code block in content/ mirrors the matching examples/*.zig file
and has been compiled against the target Zig version.
- Hello, World
- Values
- Variables
- Integers
- Floats
- Strings
- Arrays
- Slices
- Vectors
- Structs
- Enums
- Unions
- Functions
- Blocks and Statements
- If / Else
- Switch
- While Loops
- For Loops
- Defer
- Errors
- Optionals
- Pointers
- Multi-Pointers
- Slices (Pointers)
- Comptime
- Generics
- Memory Allocation
- ArrayList
- HashMap
- Linked List
- Testing
- Formatting and Print
- Io Interface — new in 0.16
- Writer & Reader — new
- File I/O
- Threading & Concurrency — new
- Processes
- Networking & HTTP — new
- JSON
- Random Numbers
- Sorting
- Math
- Build System
- C Interop
Install Zig 0.16.0 — brew install zig on macOS, or grab a tarball from
ziglang.org/download. Then:
$ zig run examples/01-hello-world.zig
Hello, World!
A few examples need extra flags:
$ zig test examples/31-testing.zig # tests
$ zig run examples/44-c-interop.zig -lc # link libc
- Zig Official Documentation
- Zig Standard Library Source
- Zig 0.15.1 Release Notes — Writergate, unmanaged collections
- Zig 0.16.0 Release Notes — the
Iointerface - Ziglings — exercises
Zig by Example is inspired by Go by Example by Mark McGranaghan. Examples target Zig 0.16.
Contributions welcome — see CONTRIBUTING.md.