🎓 A1Learner
🔍
0 of 46 lessons completed

Zig Intermediate Introduction

The Zig Intermediate course is a deeper study of Zig for readers who finished Zig Beginner. It works through nine areas in order, each one building on the last.

A first program

This course starts where Beginner ended, so a plain program still runs exactly as before.

const std = @import("std");

pub fn main() !void {
    const out = std.io.getStdOut().writer();
    try out.print("Intermediate Zig starts here.\n", .{});
}

The areas in order

The course works through nine areas in order, and this program prints their names.

const std = @import("std");

pub fn main() !void {
    const out = std.io.getStdOut().writer();
    try out.print("memory\nerror handling\ncomptime\ntypes\nconcurrency\ntesting\nbuild system\nC interop\nprojects\n", .{});
}

Small steps

Each lesson adds one idea at a time, and each idea is shown in a short program first.

const std = @import("std");

pub fn main() !void {
    const out = std.io.getStdOut().writer();
    const total = 2 + 3;
    try out.print("total={d}\n", .{total});
}

Example

const std = @import("std");

pub fn main() !void {
    const out = std.io.getStdOut().writer();
    try out.print("Ready for Intermediate Zig.\n", .{});
    try out.print("First stop: memory.\n", .{});
}

Key points

  • Memory is the first area, and it studies allocators that free many values at once and allocators that check for leaks.
  • Error handling is the second area, and it studies error sets and error recovery in depth.
  • Comptime is the third area, and it studies code that runs while the program is being built.
  • Types is the fourth area, and it studies struct and union shapes that control layout and safety.
  • The later areas are concurrency, testing, and build system.
  • C interop is the eighth area, and it studies calling C code from Zig.
  • Projects is the last area, and it combines the earlier areas into four complete programs.

The program prints two lines. The first line states the goal. The second line names the first area.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which area does the Zig Intermediate course study first?