iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌿

Hello World in Zig

に公開

Introduction

In this article, I will walk through the process from installing Zig to outputting "Hello World".

Environment

  • macOS Ventura

Installation

According to the official website, there seem to be several installation methods, but this time I will use Homebrew.

brew install zig

After the installation is complete, run zig version.

zig version
0.10.1

At the time of writing this article, 0.10.1 appears to be the latest version.

Outputting Hello World

Create hello_world.zig in any directory and write the following content.

hello_world.zig
const std = @import("std");

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

After saving, run zig run hello_world.zig.

zig run hello_world.zig 
Hello, World!

If it displays correctly, you've succeeded.

GitHubで編集を提案

Discussion