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.

#DescriptionLink
1Hello, WorldView
2Variables and TypesView
3Control FlowView
4Functions and deferView

The Core of Zig

comptime, pointers, optionals, and errors — the PHASE 3 pillars.

#DescriptionLink
5comptime GenericsView
6Pointers and SlicesView
7Optionals and orelseView
8Errors as ValuesView

Memory & Data

Allocators, strings, and data modeling from PHASE 4.

#DescriptionLink
9Allocators: GPA and ArenaView
10Strings and FormattingView
11Structs and Tagged UnionsView

Tooling

Files, testing, and command-line programs from PHASE 5.

#DescriptionLink
12File I/OView
13Unit Tests and LeaksView
14Command-Line ArgumentsView