Zig by Example
Zig by Example
Zig is a general-purpose programming language and toolchain for maintaining robust, optimal and reusable software. Please read the official documentation to learn more. Zig 是一门通用编程语言和工具链,旨在维护健壮、高效且可复用的软件。请阅读官方文档以了解更多信息。
Zig by Example is a hands-on introduction to Zig using annotated example programs. The examples are written for version 0.16. Check which version you’re using if something isn’t working. 《Zig 示例》(Zig by Example)是一份通过带注释的示例程序对 Zig 进行的实践性介绍。这些示例基于 0.16 版本编写。如果遇到问题,请检查你所使用的版本。
Getting Started (入门)
Hello, World! (Hello, World!) Formatted Output (格式化输出) Unit Tests (单元测试)
Basic Types (基本类型)
Variables (变量) Illegal Behavior (非法行为) Build Modes (构建模式) Basic Types (基本类型) Integers (整数) Integer Operators (整数运算符) Floating-point Numbers (浮点数)
Functions and Errors (函数与错误)
Functions (函数) Errors (错误) Assertions (断言)
Control Flow (控制流)
If Statements (If 语句) Switch Statements (Switch 语句) While Loops (While 循环) For Loops (For 循环) Blocks (代码块) Defer (Defer) Errdefer (Errdefer)
Compound Types (复合类型)
Arrays (数组) Slices (切片) Pointers (指针) Optionals (可选类型) Structs (结构体) Tuples (元组) Enums (枚举) Unions (联合体) Tagged Unions (标签联合体)
Standard Library (标准库)
Allocators (分配器) ArrayList (动态数组) AutoHashMap (自动哈希映射) StringHashMap (字符串哈希映射) HashMap (哈希映射) Sorting (排序) Random (随机数)
Command-line Programs (命令行程序)
Arguments (参数) Environment Variables (环境变量) Exit Status (退出状态)
Async/Await and I/O (异步/等待与 I/O)
Async (异步) Io Implementations (I/O 实现) Queue (队列) File System (文件系统) Text I/O (文本 I/O) Binary I/O (二进制 I/O)
Comptime (编译期)
Comptime (编译期) Precomputed Data (预计算数据) Generic Functions (泛型函数) Generic Types (泛型类型) Reflection (反射)
Zig Tooling (Zig 工具链)
Build System (构建系统) Zig and C (Zig 与 C) Using C (使用 C) C Types (C 类型) Time and Date (时间和日期)