Zig 示例
摘要
Zig by Example 是一本 Zig 编程语言的实践入门教程,包含针对版本 0.16 的带注释的示例程序。
<p>受著名的 <a href="https://gobyexample.com/" rel="ugc">Go by Example</a> 启发</p>
<p><a href="https://lobste.rs/s/s75zd9/zig_by_example">评论</a></p>
查看缓存全文
缓存时间: 2026/07/25 14:04
# Zig 入门示例
来源:https://zigbyexample.neocities.org/
Zig(https://ziglang.org/)是一门通用编程语言及工具链,旨在构建稳健、高效且可复用的软件。请阅读官方文档(https://ziglang.org/documentation/0.16.0/)了解更多信息。
*Zig 入门示例* 通过带注释的示例程序,为你提供实践性的 Zig 入门指引。
**示例基于 0.16 版本编写。** 若遇到运行问题,请检查你使用的版本。
## 开始上手
- Hello, World!(https://zigbyexample.neocities.org/hello-world.html)
- 格式化输出(https://zigbyexample.neocities.org/formatted-output.html)
- 单元测试(https://zigbyexample.neocities.org/unit-tests.html)
- 基本类型(https://zigbyexample.neocities.org/basic-types.html)
- 变量(https://zigbyexample.neocities.org/variables.html)
- 非法行为(https://zigbyexample.neocities.org/illegal-behavior.html)
- 构建模式(https://zigbyexample.neocities.org/build-modes.html)
## 基本类型
- 整数(https://zigbyexample.neocities.org/integers.html)
- 整数运算符(https://zigbyexample.neocities.org/integer-operators.html)
- 浮点数(https://zigbyexample.neocities.org/floating-point-numbers.html)
## 函数与错误
- 函数(https://zigbyexample.neocities.org/functions.html)
- 错误(https://zigbyexample.neocities.org/errors.html)
- 断言(https://zigbyexample.neocities.org/assertions.html)
## 控制流
- If 语句(https://zigbyexample.neocities.org/if-statements.html)
- Switch 语句(https://zigbyexample.neocities.org/switch-statements.html)
- While 循环(https://zigbyexample.neocities.org/while-loops.html)
- For 循环(https://zigbyexample.neocities.org/for-loops.html)
- 块(https://zigbyexample.neocities.org/blocks.html)
- Defer(https://zigbyexample.neocities.org/defer.html)
- Errdefer(https://zigbyexample.neocities.org/errdefer.html)
## 复合类型
- 数组(https://zigbyexample.neocities.org/arrays.html)
- 切片(https://zigbyexample.neocities.org/slices.html)
- 指针(https://zigbyexample.neocities.org/pointers.html)
- 可选类型(https://zigbyexample.neocities.org/optionals.html)
- 结构体(https://zigbyexample.neocities.org/structs.html)
- 元组(https://zigbyexample.neocities.org/tuples.html)
- 枚举(https://zigbyexample.neocities.org/enums.html)
- 联合体(https://zigbyexample.neocities.org/unions.html)
- 标签联合体(https://zigbyexample.neocities.org/tagged-unions.html)
## 标准库
- 分配器(https://zigbyexample.neocities.org/allocators.html)
- ArrayList(https://zigbyexample.neocities.org/arraylist.html)
- AutoHashMap(https://zigbyexample.neocities.org/autohashmap.html)
- StringHashMap(https://zigbyexample.neocities.org/stringhashmap.html)
- HashMap(https://zigbyexample.neocities.org/hashmap.html)
- 排序(https://zigbyexample.neocities.org/sorting.html)
- 随机数(https://zigbyexample.neocities.org/random.html)
## 命令行程序
- 参数(https://zigbyexample.neocities.org/arguments.html)
- 环境变量(https://zigbyexample.neocities.org/environment-variables.html)
- 退出状态(https://zigbyexample.neocities.org/exit-status.html)
## 异步/等待与 I/O
- 异步(https://zigbyexample.neocities.org/async.html)
- I/O 实现(https://zigbyexample.neocities.org/io-implementations.html)
- 队列(https://zigbyexample.neocities.org/queue.html)
- 文件系统(https://zigbyexample.neocities.org/file-system.html)
- 文本 I/O(https://zigbyexample.neocities.org/text-io.html)
- 二进制 I/O(https://zigbyexample.neocities.org/binary-io.html)
## 编译期计算
- Comptime(https://zigbyexample.neocities.org/comptime.html)
- 预计算数据(https://zigbyexample.neocities.org/precomputed-data.html)
- 泛型函数(https://zigbyexample.neocities.org/generic-functions.html)
- 泛型类型(https://zigbyexample.neocities.org/generic-types.html)
- 反射(https://zigbyexample.neocities.org/reflection.html)
## Zig 工具
- 构建系统(https://zigbyexample.neocities.org/build-system.html)
## Zig 与 C
- 使用 C(https://zigbyexample.neocities.org/using-c.html)
- C 类型(https://zigbyexample.neocities.org/c-types.html)
- 时间与日期(https://zigbyexample.neocities.org/time-and-date.html)
Zig 入门示例(https://zigbyexample.neocities.org/index.html)·关于(https://zigbyexample.neocities.org/about.html)·源码(https://codeberg.org/levin/zigbyexample)
相似文章
Zig 示例教程
通过带注释的示例,对 Zig 编程语言进行实践性介绍,涵盖从基础到高级的主题。灵感来源于 Go by Example。
重返Zig
作者描述了从Zig到Rust再回到Zig的历程,探讨了编程语言中稳定性与表达力之间的权衡。
为什么我在2024年用Zig编写了一个Game Boy Advance游戏
一位开发者解释了为什么他们选择Zig编程语言来创建Game Boy Advance游戏,强调了Zig的交叉编译能力及其对嵌入式编程的适用性。
以Zig风格构建你的项目
作者详细介绍了构建一个名为bygge-zig的工具,该工具使用Zig构建系统来编译Rust项目,用更少的代码行复制了Cargo的功能,并突出了其中的差异和挑战。
用 Zig 写一个 C 编译器
一位开发者记录了用 Zig 语言、按照 Nora Sandler 的教程系列构建名为 paella 的 C 编译器的全过程。