Zig by Example
Zig by Example

Hello, World

< 1 min read

Hello, World

Every Zig program starts at pub fn main.

const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, World!\n", .{});
}

@import is a built-in that pulls in a module — std here is the standard library. std.debug.print writes to stderr, which is handy because it needs no buffer and no Io instance. For stdout you'll wire up a Writer (see chapter 32).

$ zig run examples/01-hello-world.zig
Hello, World!
Zig by Example
Zig by Example

by Dariush Abbasi

A hands-on introduction to Zig via annotated examples. Covers the language from Hello World through memory allocation, concurrency, networking, and C interop.

View book →