Free Zig Tutorials
25 free, hands-on Zig lessons from first lines of code to advanced patterns. Run every example directly in your browser — no install, no signup.
basics
Introduction to Zig
Learn how to install Zig and get started with systems programming — covers setup on macOS, Linux, and Windows plus your first program
Variables and Data Types
Master Zig variables and the Zig type system — declare const and var bindings, use type inference, and convert between numeric types safely.
Functions
Learn Zig functions — define function parameters and return types, use public vs private visibility, and pass function pointers for flexible code.
Control Flow
Master Zig control flow — use if expressions, while and for loops, and switch expressions with pattern matching to write concise, safe logic.
Arrays and Structs
Learn Zig arrays and structs — create fixed-size arrays, define structs with methods, and organize data structures for clean, efficient programs.
Enums And Tagged Unions
Learn Zig enums and tagged unions — model state with named values, attach data to variants, and use exhaustive switch for type-safe dispatch.
intermediate
Error Handling
Master Zig error handling — use error unions, error sets, try/catch, and errdefer to write robust code that fails gracefully without exceptions.
Memory and Allocators
Understand Zig memory management — compare stack vs heap allocation, use allocator interfaces, and avoid leaks with explicit manual memory control.
Zig Comptime — Compile-Time Programming Guide
Zig comptime tutorial — learn compile-time evaluation, comptime parameters, type reflection, and how to write generic zero-cost abstractions. Free tutorial with runnable examples.
Optionals and Unions
Learn the Zig optional type and null safety — use ?T to represent nullable values, unwrap safely with orelse and if, and match on tagged unions.
Slices and Iteration
Master Zig slices and iteration — use fat pointers for safe array views, iterate with for loops, and leverage std.mem utilities for searching and splitting.
Pointers And References
Master Zig pointers — take addresses with &, dereference with .*, understand *T vs [*]T vs []T, and pass data by reference for efficient code.
String Handling
Learn Zig string handling — work with []const u8 byte slices, compare and search strings, iterate bytes, and build strings with std.fmt.
Generics And Anytype
Learn Zig generics and anytype — write reusable, type-safe functions using comptime type parameters with zero runtime overhead.
Zig File I/O
Read and write files in Zig with std.fs — open file handles, use buffered readers and writers, manage directories, and handle I/O errors explicitly.
Data Structures
Use Zig data structures — build dynamic collections with std.ArrayList, store key-value pairs in std.HashMap, and create your own generic types.
Zig Packaging and Modules — Project Structure Guide
Structure Zig projects with modules — use @import for file-based modules, control visibility with pub, and manage packages with build.zig.zon. Free tutorial with examples.
advanced
Async I/O
Learn non-blocking I/O, event loops, and polling-based concurrency patterns in Zig for high-performance applications
Testing
Write Zig unit tests using built-in test blocks and std.testing — run tests with zig test, assert values, and detect memory leaks automatically.
Zig Build System — build.zig Tutorial
Learn the Zig build system — configure build.zig for compilation, testing, and dependencies without Make or CMake. Free hands-on tutorial with runnable examples.
Zig C Interop — Call C from Zig Guide
Call C from Zig with zero overhead — use @cImport to include C headers, link C libraries, and pass data between Zig and C seamlessly. Free tutorial with examples.
Capstone Project
Build a complete Zig command-line tool — combine allocators, error handling, slices, structs, and testing into a real data processing utility.
Interfaces and Vtables
Implement Zig interfaces using vtables — use tagged unions for closed dispatch and function pointer structs for open, runtime polymorphism.
SIMD and Vectors
Use Zig SIMD with @Vector — perform element-wise operations, reduce vectors to scalars, and write data-parallel code targeting real CPU instructions.
Error Handling Patterns
Go beyond basic Zig error handling — define custom error sets, use errdefer for cleanup, merge error sets, and switch on specific errors for recovery.