Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is Zig?

Meet Zig, a small systems programming language with no hidden control flow, no hidden allocations and compile-time code execution. Learn what it is for and how it compares.

Zig is a general-purpose systems programming language and toolchain. You use it for the same kinds of programs you would write in C: operating system components, game engines, databases, command-line tools, embedded firmware, and libraries that other languages call into. Zig aims to be a better C: simpler than C++ or Rust, but with far fewer traps than C itself.

Zig is still before version 1.0, so details of the standard library change between releases. This course teaches the language core, which changes slowly, and points out the places where recent releases (0.15 and newer) differ from older tutorials you may find online.

Zig is not available on this site's code runners. Zig examples in this course are read-only. Where a concept is easy to demonstrate in another language, you get a clearly labelled stand-in in C or Rust that you can run here. Zig output is only shown when it is certain.

The core ideas

Zig is easiest to understand through the things it refuses to do.

Zig in four ideas

No hidden control flow No operator overloading, no exceptions, no destructors
No hidden allocations Memory comes from an allocator you pass in
Comptime Ordinary Zig code runs at compile time
C interop Import C headers and build C code directly

If you can read the code, you can see everything it does.

1 / 2

No hidden control flow. When you read a + b in Zig, it is integer or float addition and nothing else; a call to a function always looks like a call. There are no exceptions that jump out of nowhere and no destructors that run behind your back. If code runs, you can point at the line.

No hidden memory allocation. The standard library never allocates on its own. Any function that needs heap memory takes an Allocator parameter, so the caller decides where memory comes from, and a leak or an out-of-memory error is always visible in the code. Allocators get their own chapter later in the course.

Comptime instead of macros and templates. Zig can run normal functions while compiling. Generic containers, lookup tables and conditional code are written in the same language as everything else, with no separate preprocessor or template syntax.

First-class C interop. Zig can @cImport a C header, call C libraries, and even act as a drop-in C compiler (zig cc), which makes it a popular cross-compilation tool for C and C++ projects.

What Zig code looks like

Here is a complete program. Do not worry about understanding every token yet; the next lessons cover each part.

ZIG
const std = @import("std");

pub fn main() void {
    const name = "Zig";
    var count: u32 = 0;
    while (count < 3) : (count += 1) {
        std.debug.print("Hello from {s}, round {d}\n", .{ name, count });
    }
}

Running it prints three lines:

TEXT
Hello from Zig, round 0
Hello from Zig, round 1
Hello from Zig, round 2

Notice the shape: const and var declare names, types come after the name (count: u32), blocks use braces, and statements end with semicolons. If you know C, Go or Rust, it will feel familiar within a day.

Zig compared with other languages

C C++ Rust Go Zig
Memory management manual manual + RAII ownership and borrowing garbage collector manual, explicit allocators
Hidden code paths few (macros) many some (Drop, traits) some (GC, goroutines) none by design
Generics macros templates traits + generics generics comptime
Error handling return codes exceptions Result error values error unions with try
Build system external (make, CMake) external Cargo go build built in, written in Zig
Runtime tiny small tiny large (GC, scheduler) none by default

Zig does not have Rust's borrow checker. It gives you explicit tools instead: allocators that detect leaks and double frees in tests, runtime safety checks in Debug builds, and a type system that makes null, errors and integer sizes visible. You are responsible for lifetimes, as in C, but the compiler and standard library catch many more mistakes.

Where Zig is used

  • Systems and tools: the Bun JavaScript runtime and the Ghostty terminal emulator are written in Zig, and the Zig compiler itself is written in Zig.
  • Embedded and WebAssembly: no runtime and tiny binaries make it a good fit for microcontrollers and wasm32 targets.
  • Cross-compilation: a single Zig download can build for Linux, Windows, macOS and many other targets without extra SDKs.
  • Replacing C build pain: teams use zig cc and zig build to compile existing C and C++ code.

A tiny stand-in you can run

One of Zig's habits is to make memory and cost visible. This C stand-in mimics the explicit style: the caller owns the buffer and passes it in, so nothing allocates behind the scenes.

C Stand-in (C): the caller provides the memory

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Zig would express the same design with a slice parameter (out: []u8) and an error union return value; you will write exactly that later in the course.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does 'no hidden control flow' mean in Zig?

    Zig avoids features that execute code invisibly, such as exceptions, overloaded operators and destructors.
  2. 2. Who decides where heap memory comes from in Zig code?

    Functions that need memory take an Allocator parameter, so allocation is always visible.
  3. 3. Which Zig feature replaces C macros and C++ templates for generic code?

    Comptime runs ordinary Zig code during compilation, which is how generic types and compile-time tables are written.
  4. 4. Can you use Zig as a C compiler?

    The zig cc command wraps Clang with Zig's cross-compilation support.

Summary

  • Zig is a systems language meant as a safer, simpler alternative to C, with no hidden control flow and no hidden allocations.
  • Memory is managed explicitly through allocators the caller passes in.
  • Comptime lets ordinary code run at compile time, replacing macros and templates.
  • Zig reads C headers, builds C code and cross-compiles from one small download.
  • The language is pre-1.0, so library details change between releases.

Next: Installing Zig