Skip to content

Zig Intro

Zig is a systems programming language. You’d use it for the same jobs as C: command-line tools, game engines, embedded devices, databases and anything else where speed and control over memory matter.

Its big promise is that it’s simple and has no surprises. There are no hidden function calls, no hidden memory allocations and no macros. If a line of code doesn’t look like it calls a function, it doesn’t.

Zig was started by Andrew Kelley in 2016. Today it’s developed in the open and supported by the non-profit Zig Software Foundation.

C has been around for 50 years and it still runs most of the world’s low-level code. But it comes with a lot of baggage: a preprocessor full of tricks, undefined behavior that’s easy to hit, and build systems that are hard to set up.

Zig keeps what people like about C (speed, small programs, full control) and fixes the rough edges:

  • Memory is always explicit. A function that needs memory takes an allocator as a parameter, so you can see exactly where memory comes from.
  • Errors are values you can’t ignore. If a function can fail, the compiler makes you deal with it.
  • Code can run at compile time. The comptime keyword replaces C’s macros with normal Zig code.
  • It talks to C directly. You can include C headers and call C functions with no wrapper code.

A rough map of where Zig sits next to languages you might know:

Language Speed How memory is managed Garbage collector
C Fast By hand, easy to get wrong No
Go Good Automatically Yes
Rust Fast Ownership rules checked by the compiler No
Zig Fast By hand, through allocators you pass around, with safety checks in debug builds No

The takeaway: Zig gives you C-level control, but makes memory and errors much easier to see.

  • Bun: the fast JavaScript runtime is written in Zig
  • TigerBeetle: a financial database built for speed and safety
  • Ghostty: a popular terminal app
  • As a C compiler: zig cc can build C code for other platforms, and some teams use it just for that

You don’t need to understand every detail yet:

const std = @import("std");
pub fn main() void {
const name = "Zig learner";
std.debug.print("Hello, {s}!\n", .{name});
}

Output:

Hello, Zig learner!

The {s} is a placeholder for a string, and .{name} is the list of values to put into the placeholders.

If you’ve written some C, Zig will feel familiar within a day or two. If you’re coming from Python or JavaScript, the new part is managing memory yourself. That takes some getting used to, but Zig makes it easier than C does, because every allocation is out in the open.

  • Zig is a small, fast systems language with no hidden control flow.
  • Memory is managed by hand, through allocators you can see.
  • Errors must be handled, and comptime replaces macros.
  • It’s used in Bun, TigerBeetle and Ghostty, and as a C compiler.

Next up: installing Zig and running your first program.

Quick check

1. How does a Zig function get memory when it needs some?

2. What does Zig use instead of C-style macros?

3. Which popular JavaScript runtime is written in Zig?

Score: 0 / 3