Zig

Learn Zig: explicit control flow, slices and pointers, errors and optionals, allocators, comptime generics, C interop, cross-compiling, build.zig and tests.

Start course →

What you'll learn

  • Explain Zig's design principles and use the zig toolchain, build modes and project layout.
  • Write Zig with explicit types and casts, control-flow expressions, arrays, slices, strings and pointers.
  • Model data with structs, enums and tagged unions, and handle failures with error unions and optionals.
  • Manage memory with allocators, defer and errdefer, and use standard containers safely.
  • Use comptime for constants, generics and reflection, and understand safety checks and integer semantics.
  • Interoperate with C, cross-compile, build and test with build.zig, and write concurrent, efficient code.

Syllabus

Getting Started with Zig

  1. What Zig Is and Why It Exists
  2. Installing Zig and Using the Toolchain
  3. Variables, Types and Integers

Control Flow, Arrays, Slices and Pointers

  1. if, while, for, switch and Labelled Blocks
  2. Arrays, Slices and Strings
  3. Pointers and Optional Pointers

Structs, Unions and Error Handling

  1. Structs, Methods and Namespaces
  2. Enums, Tagged Unions and Exhaustive switch
  3. Errors, Optionals, try, catch and errdefer

Memory and Allocators

  1. Allocators: Explicit Memory Management
  2. defer, errdefer and Ownership
  3. ArrayList, HashMap and Other Containers

Compile-Time Programming

  1. comptime Basics
  2. Generic Types and Functions
  3. Reflection with @typeInfo and anytype

Safety, C Interop and Cross-Compilation

  1. Integer Semantics, Safety Checks and Undefined Behaviour
  2. Interoperating with C
  3. Cross-Compilation and zig cc

The Build System, Packages and Testing

  1. build.zig: Builds as Zig Code
  2. Packages and Dependencies with build.zig.zon
  3. Testing in Zig

Concurrency, Performance, Idioms and Revision

  1. Threads, Atomics and Synchronisation
  2. Low-Level Performance: Layout, SIMD and Buffered I/O
  3. Idiomatic Zig and Common Pitfalls
  4. Revision and Interview Questions