Zig Demo Examples
Practice programs, one file each. Every demo is self-contained — copy it, modify it, and run it. Each file
@imports only the standard library, so nothing else needs installing.
How to use: click View to open a file in the code viewer, read its comments, download it to your machine, and run it with the Zig toolchain. Most demos need only zig run <file>; the tests demo uses zig test.
zig run 01_hello.zig # compile and run
zig test 13_tests.zig # compile and run the test blocks
Foundations
Syntax, variables, control flow, and functions from PHASE 1 and 2.
| # | Description | Link |
|---|---|---|
| 1 | Hello, World | View |
| 2 | Variables and Types | View |
| 3 | Control Flow | View |
| 4 | Functions and defer | View |
The Core of Zig
comptime, pointers, optionals, and errors — the PHASE 3 pillars.
| # | Description | Link |
|---|---|---|
| 5 | comptime Generics | View |
| 6 | Pointers and Slices | View |
| 7 | Optionals and orelse | View |
| 8 | Errors as Values | View |
Memory & Data
Allocators, strings, and data modeling from PHASE 4.
| # | Description | Link |
|---|---|---|
| 9 | Allocators: GPA and Arena | View |
| 10 | Strings and Formatting | View |
| 11 | Structs and Tagged Unions | View |
Tooling
Files, testing, and command-line programs from PHASE 5.
| # | Description | Link |
|---|---|---|
| 12 | File I/O | View |
| 13 | Unit Tests and Leaks | View |
| 14 | Command-Line Arguments | View |