Outline updated November 2026
Zig Essentials
Class Duration
21 hours of live training delivered over 3 days.
Student Prerequisites
- Prior programming experience in some language (C, C++, Rust, Go, or similar is ideal)
- Comfort with the command line and a compiler-based workflow
- No prior Zig experience required
Target Audience
- Developers who want to write fast, explicit, and maintainable software in Zig
- Teams evaluating Zig for systems programming, tools, libraries, or embedded work
- Experienced C and C++ developers may prefer the translation-focused Zig for C and C++ Programmers
- Teams continuing on can move to The Zig Build System and Cross-Compilation
Description
Zig Essentials teaches the Zig language and toolchain, a systems language that improves on C. Zig adds optionals and required error handling, and it passes allocators as explicit parameters. Students start with data types, control flow, code organization, and memory management with defer and errdefer. The course then covers comptime, allocator design, and the std.Io interface. It ends with the build system, testing, safety-checked build modes, and C interop.
Learning Outcomes
- Build, run, and test Zig programs with the Zig toolchain and build system.
- Explain what sets Zig apart and where it is a good fit.
- Apply Zig's memory control, optionals, and error handling.
- Choose, compose, and test allocators, and detect leaks in tests.
- Use comptime for generic, reflective, zero-cost code.
- Write code against the
std.Iointerface. - Run tasks asynchronously and concurrently with futures and groups.
- Select build modes and explain the safety checks in each.
- Plan where Zig can work alongside or replace C in an existing codebase.
Training Materials
All students receive comprehensive courseware covering all topics in the course. Courseware is distributed via GitHub in the form of documentation and extensive code samples. Students practice the topics covered through challenging hands-on lab exercises.
Software Requirements
Students will need a free, personal GitHub account to access the courseware. Students will need permission to install Zig 0.17 and Visual Studio Code (with the Zig language extension) on their computers. No separate C compiler is required, because the Zig toolchain compiles the C code used in class. Also, students will need permission to install Visual Studio Code extensions. If students are unable to configure a local environment, a cloud-based environment can be provided.
Training Topics
Why Zig?
- What Zig is
- Problems Zig solves
- Zig compared to C
- Zig compared to other languages
- Zig Zen
- Release cadence and the road to 1.0
Getting Started
- The Zig toolchain
- Hello, Zig!
- Coding and debugging in VS Code
- The Zig standard library
- Zig source files
- Cross-compilation
Language Features in Hello Zig
- Importing from the standard library
- Constants
- A public
mainfunction - The
std.process.Initparameter - Allocator,
Io, and arguments fromInit - The
trykeyword - Error union types
- Format strings and format arguments
- Comments
Zig Project Scaffolding
- Creating an executable project
- Creating a library project
- Build and run
- Build and test
Console Apps
- Buffered terminal output
- Format specifiers
- Anonymous struct literals as format arguments
- Reading terminal input
- String comparison
whileloops- Error handling
Data Types and Data Structures
- Integers and floats
- Arrays, pointers, and slices
- Optionals
- Structs
- Enums
- Unions and tagged unions
Variables
- Variable naming rules
- Container-level variables
- Compile-time vs. run-time variables
- Local variables
Control Flow
- Expressions and operators
whileandforloops- Labeled blocks and loops
breakandcontinueifstatementsswitchstatementstryandcatchdeferanderrdefer
Functions
- Defining and calling functions
- Passing parameters
- Immutable vs. mutable parameters
- Importing functions from other Zig files
Strings
- Strings as UTF-8 byte slices
- String literals and sentinel-terminated arrays
- Buffers
- Printing formatted strings
- Capturing strings from console input
- Copying and comparing strings with
std.mem
Program a Zig "Object"
- Compared to C, C++, Python, and JavaScript
- Files as structs
- Data fields and constant fields
- Methods and the
init/deinitconvention - Error sets as part of an API
- Dynamic memory allocation for struct members
Errors and Error Handling
- Inferred, explicit, and merged error sets
- Error union types and
try - Handling errors with
catchandswitch errdeferand partial-initialization cleanup- Error return traces
Memory Control and Allocators
- No hidden allocations
- Memory control vs. memory safety
- The
Allocatorinterface - Passing allocators as parameters
- Page, arena, and fixed-buffer allocators
- General-purpose allocators
- Leak and double-free detection with
SafeAllocator - Lifetime-scoped allocation with arenas
- Heap allocation failure
- Lifetime and ownership
- Optionals and optional pointers
- Null references
- Writing a wrapping allocator
- Leak detection with
std.testing.allocator - Allocation failure injection in tests
Comptime
- Types as first-class values
comptimeparameters, variables, and blocks- Generic functions and data structures
- Reflection with
@TypeOfand@typeInfo - Lookup tables at compile time
- Branch quotas and comptime limits
- Comptime vs. macros and templates
I/O with std.Io
- Passing
Ioas a parameter Io.ReaderandIo.Writer- Explicit buffering
- Files and directories through
Io io.asyncvs.io.concurrent- Futures with
awaitandcancel - Managing many tasks with
Io.Group - Cancellation and
error.Canceled - The defer-cancel pattern
Io.Threadedas the default- Experimental backends such as
Io.Evented - Writing Io-generic libraries
The Zig Build System
build.zigandbuild.zig.zon- Declaring dependencies with
zig fetch - Creating modules and executables
- Cross-compilation targets
- Adding C sources and linking C libraries
- C headers via the translate-c package
Testing
- Built-in tests with
test "name" { ... } - What can be tested
- Asserting with
try expect std.testing.expectEqual,expectError, andexpectEqualStrings- Testing Io-generic code
- Built-in fuzzing with
zig build test --fuzz
Build Modes and Safety
- Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall
- Bounds and overflow checks
- Null unwrap and unreachable checks
- Illegal behavior vs. undefined behavior
- Choosing a build mode