Hello, World!

This program prints Hello, world! to the terminal:

const std = @import("std");

pub fn main(init: std.process.Init) !void {
    try std.Io.File.stdout().writeStreamingAll(
        init.io,
        "Hello, world!\n",
    );
}

We can run it directly:

$ zig run hello.zig
Hello, world!

Or build an executable first:

$ zig build-exe hello.zig
$ ./hello
Hello, world!

std.debug.print

std.debug.print is a simple way to print to standard error:

const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, world!\n", .{});
}
$ zig run hello-2.zig 
Hello, world!

Next example: Formatted Output.