Zig · Interactive Curriculum
Learn Zig Online
With a Zig Playground
A free interactive Zig tutorial with an online compiler for comptime, allocators, C interop, manual memory management, SIMD, and systems programming practice.
1const std = @import("std");23pub fn main(init: std.process.Init) !void {4 var buffer: [1024]u8 = undefined;5 var stdout_writer = std.Io.File.stdout().writer(init.io, &buffer);6 const stdout = &stdout_writer.interface;78 try stdout.print("Hello, Zig!\n", .{});9 try stdout.flush();10}Coming from C/C++?
Skip the basics and jump straight to what makes Zig different.
Why Learn Zig?
Discover the benefits of learning Zig for systems programming.
No Hidden Control Flow
Predictable code with no hidden allocations, exceptions, or operator overloading.
All Zig Lessons
Browse the complete ordered curriculum. Each lesson has a readable page you can link to and share.
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.
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 preview tagged unions for values with more than two shapes.
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.
Async I/O with std.Io
Learn Zig 0.16's async I/O model — thread Io through your code like an allocator, launch tasks with io.async, await futures, fan out with std.Io.Group, and cancel work you no longer need.
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.
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.
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.Io.Dir — 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.
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.
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.
Frequently Asked Questions
- Can I learn Zig here for free?
- Yes. LearningZig.org is free, with lessons and an online Zig playground that take you through comptime, allocators, C interop, pointers, build systems, and systems programming.
- Can I run Zig without installing it?
- Yes. The playground compiles and runs Zig right in the browser, which is handy for trying things out before you set up a local toolchain.
- Is this worth it if I already write C or Rust?
- Yes. There are paths aimed at systems programmers, so you can see how Zig handles allocators, comptime, C interop, error handling, and low-level control and weigh it against what you already do in C, C++, or Rust.
- What should I learn first in Zig?
- Start with the fundamentals, variables, functions, control flow, arrays, structs, and error handling, then get a feel for memory allocators and comptime before you take on C interop and build systems.