Home / Zig
Zig
Zig taught as plain programs: variables and types, control flow and functions, arrays, slices and strings, structs and enums, error sets, pointers and allocators, and comptime generics. Every example is verified with the real compiler.
Zig is a language that hides nothing from you. When a Zig program moves memory or stands a chance of failing, the code says so in plain sight, and that honesty is the habit this course builds first. You begin with a single printed line and finish with pointers, allocators and two working programs of your own.
Course contents
Work top to bottom — the sidebar is the course. Topics later in the list assume the ones before them.
Zig Introduction
Beginner · ⏱ 3 min · standalone lesson
Getting Started
Start: Zig Get Started ❯Numbers and Operators
Start: Zig Arithmetic ❯Control Flow
Start: Zig If Else ❯Functions
Start: Zig Functions ❯Arrays and Slices
Start: Zig Arrays ❯Structs and Enums
Start: Zig Structs ❯Error Handling
Start: Zig Error Sets ❯Pointers and Memory
- Zig Pointers
- Zig Pointers and Functions
- Zig Many-Item Pointers
- Zig Allocators
- Zig Dynamic Arrays
- Zig Freeing Memory
Comptime and Generics
Start: Zig Comptime ❯Everyday Tools
Start: Zig Formatting ❯Zig Project: Grade Tracker
Beginner · ⏱ 5 min · standalone lesson
Zig Project: Bank Account
Beginner · ⏱ 5 min · standalone lesson
Learn Zig
Zig is a programming language for building fast, sturdy software, from small command-line tools to whole operating systems. A Zig program is checked by the compiler and turned into machine code before it runs, so the finished program starts at once and needs no helper runtime beside it.
People pick Zig when they want control they can see. There is no hidden control flow: a line of Zig does the work it appears to do, and nothing leaps away behind your back. Memory is handled in the open as well, because any value that needs room has to ask an allocator for that room.
This beginner course introduces Zig the way the language itself behaves: plainly, and one visible step at a time. Pointers and allocators show up early enough to stop being mysterious, and comptime, Zig’s way of running code while compiling, arrives as a first look rather than a riddle.
What you will learn
The lessons walk from a first print to the ideas Zig is known for. By the closing projects, you can do all of the following:
- Set up the shape every program in this course keeps: one file called main.zig, a main function, and a writer that sends text to the screen.
- Store whole numbers and decimal numbers in typed variables, and handle arithmetic that divides the way Zig specifies, truncating toward zero.
- Direct a program with if and switch, repeat work with while and for, and schedule tidy-up with defer so it runs the moment a block ends.
- Write functions with typed inputs and named results, call a function from inside itself through recursion, and hand a type to a function as a comptime parameter.
- Hold ordered values in arrays, view a stretch of them through a slice, and treat text as bytes you can search through and sort.
- Model your own data with structs that carry methods and default field values, and name a fixed set of choices with enums and tagged unions.
- Cope with a value that might be missing by using optionals, unwrapping one only after a check shows something is really there.
- Report failure with error sets, pass an error upward with try, catch one where you can deal with it, and clean up on the way out with errdefer.
- Follow a pointer to the value it names, change a caller’s variable through a pointer, and request room from an allocator before handing that room back.
- Write one function that adapts to many types through comptime, format and read numbers with std.fmt, and check your own code with zig test.
- Finish with two complete programs: a grade tracker that averages a set of scores and reports a letter band, and a bank account that turns away a withdrawal its balance cannot cover.
Who this Zig course is for
Complete beginners can start here. The course assumes no earlier programming at all, defines each new word where it first appears, and keeps every program small enough to hold in your head at once.
Programmers arriving from another language will find the differences named as they come up. Zig asks you to write down things other languages settle quietly, such as which values may be absent and where memory comes from, so a few early lessons move at a deliberate pace on purpose.
The 55 lessons add up to 202 minutes of reading and practice. That fits inside a week of evenings for most schedules, and the two closing projects then show you exactly how far the basics carry.
How this course works
Lessons run in one fixed order, and later pages lean on ideas the earlier ones taught. Each program keeps the same main.zig shape from the first lesson to the last, so the new idea on a page is the only unfamiliar thing on it.
Every example and snippet was compiled and run with the real Zig compiler, version 0.14.1, before the course was published. The output printed beside each program is what that compiler’s program genuinely produced, checked twice over.
Zig has no official playground on the web, so this site does not pretend to run Zig in your browser. The code and its genuine output sit on the lesson page itself, and one lesson near the end shows how zig test reports on code you write at home.
Each lesson closes with a short exercise, and its answer arrives with the reason behind it. Your finished lessons are remembered by your browser, so a half-done evening can be picked up where it stopped.
Frequently asked questions
Is this Zig course free?
Yes. Every lesson, exercise and project listed here is open to read and finish without paying, and there is no account to create before the first lesson.
Do I need to install Zig before starting this course?
No. Each program on the site arrives with its genuine output already beside it, so reading and learning work from the first page. When you are ready to run code yourself, Zig is a single download from ziglang.org, and every program here fits in one file.
Is Zig a hard first programming language?
Zig is stricter than many beginner languages, and this course treats that strictness as the lesson rather than an obstacle. Pointers and manual memory arrive in small pieces with running examples, so a first-time learner meets them as ordinary tools instead of folklore.
How long does this Zig course take to finish?
Added together, the 55 lessons hold 202 minutes of material, roughly three and a half hours. Most learners spread that across a week of evenings and keep the two projects as open-ended practice afterwards.
What kinds of programs is Zig used for?
Zig turns up in system tools, game engines, embedded software and command-line utilities, anywhere a program must be fast and careful with memory. Its compiler can also build C projects, which is how many teams first meet it.
What should I learn after this Zig beginner course?
Rust Beginner is the nearest neighbour: it tackles memory and safety with a compiler that guards both, which throws Zig’s manual approach into sharp relief. Go Beginner and C++ Beginner are the other honest next steps, and their blurbs below carry the details.
Next steps
- Rust Beginner ❯ — Rust Beginner spans 142 lessons over the same systems ground, memory, errors and types included, but its compiler checks ownership for you, a revealing contrast after Zig’s manual style.
- Go ❯ — Go Beginner runs 38 lessons through a smaller, calmer systems language, handy if you want services and tools with less ceremony once Zig’s explicitness feels familiar.
- C++ ❯ — C++ Beginner covers 40 lessons in the long-established language Zig was designed to improve on, so Zig’s choices make fuller sense with both in view.