Fast code.
No hidden tricks.

Zig is a tool used to talk to computers. It is built to replace older languages like C. It gives you total control over how your program runs, without the usual dangers and crashes.

Why do we need a new language?

For a long time, the "C" language has been the king of fast, low-level computer programs. But C has a big problem: it is very easy to make mistakes.

The C Way (Old)

C is like driving a very fast car with no seatbelts. If you make one wrong turn with computer memory, the whole program crashes. Hackers use these exact crashes to break into systems.

The Zig Way (New)

Zig is the fast car, but with seatbelts, airbags, and a map. It gives you the same raw speed as C, but it actively stops you from making those dangerous memory mistakes.

Rule #1: No Hidden Magic

RULE A

What you see is what you get

In many languages, code does things behind your back to make your life "easier." Zig does not. If you do not write it, it does not happen.

RULE B

No hidden jumps

When you read Zig code, you read it from top to bottom. The code will never secretly jump to another file or function without telling you directly.

RULE C

No hidden memory

Getting memory from the computer is a big deal. Zig forces you to be obvious when you ask for memory. There are no surprise memory tasks.

You are the Boss of the Memory

Think of computer memory like a giant room full of empty boxes. When your program needs to hold data, it takes a box.

Other languages have a robot that runs around cleaning up boxes you forgot to put away. This robot is slow. Zig does not have a robot. You must clean up your own boxes.

Because you do the cleanup yourself, Zig programs run incredibly fast. But do not worry; Zig gives you tools to make sure you never forget to clean up.

Memory Handlers (Allocators)

Page Allocator Standard
Arena Allocator Throwaway
Fixed Buffer Fast & Small

Fast. Every Single Time.

This is called "Predictable Performance".

Have you ever played a game that suddenly pauses for a split second? That is usually the game's code cleaning up old memory (the robot we talked about earlier).

In Zig, that never happens. Because you control the memory, the code runs at the exact same speed from start to finish. There are no sudden pauses. This makes Zig perfect for making video games, music software, and things that cannot ever stop.

Clean Up Later.

The `defer` superpower.

When you open a door, you must close it. When you open a computer file, you must close it. Forgetting to close things causes big problems.

Zig solves this with the word defer. It lets you write the "close" instruction right next to the "open" instruction. Zig will automatically remember to run the "close" instruction at the very end of your task.

Step 1: Open

You open the picture file to look at it.

Step 2: Defer Close

You tell Zig: "Hey, when we are done here, make sure to close this file."

Step 3: Do Work

You edit the picture. If there is an error, Zig still remembers to close it before stopping.

Time Travel for Code.

Zig can run code before your program even starts.

Compile Time (Before)

You can ask Zig to do heavy math or setup while it is building the program. By the time the user gets the program, the hard work is already finished.

comptime x = heavyMathTask();

Run Time (During)

Because the heavy math was done in the past, the running program is tiny and incredibly fast. The user never has to wait.

// The program already knows 'x' print(x);

The Empty Box Problem.

A "Null Pointer" means asking for data, but getting an empty box. In old languages, this causes an instant crash. Zig fixes this using Optionals.

The Old Way

The code assumes a box has a number inside. It reaches in blindly. If the box is empty, the program panics and crashes entirely.

NULL

The Zig Way

Zig uses a special tag (`?`) to mark boxes that might be empty. It forces you to write a rule for what to do if the box is empty before you are allowed to open it.

?Number
Check first!

Mistakes happen. Zig is ready.

No Hidden Crashes

When you write a program to open a file, what if the file is not there? Other languages might throw a hidden "Exception" that crashes your program out of nowhere.

Zig forces you to look at the mistake. If a function can fail, Zig makes you write code to handle that failure. You cannot ignore it. This means your programs are much tougher and will almost never crash by accident.

Packaging Your Data.

If you are building a game, a player has a name, a health score, and an amount of gold. Instead of keeping these separate, Zig lets you package them together in a Struct.

The Idea

A Struct is just a custom container. You define what goes inside. Every time you make a new "Player", they get their own health and gold stats.

  • + Name (Words)
  • + Health (Number)
  • + Gold (Number)
// Creating the package
const Player = struct {
    health: i32,
    gold: i32,
};

// Making a new player
var hero = Player{
    .health = 100,
    .gold = 50,
};
ZIG

Best Friends with C.

The world runs on old code written in C. Rewriting it all is impossible. Zig does not force you to rewrite.

Zig can read and run C code instantly. You can write half your project in old C, and half in new Zig, and they will talk to each other perfectly without any glue or tricky setup.

No rewriting required.

Build for Anywhere.

Normally, if you want to make a program for an Apple computer, you need to use an Apple computer. Not with Zig.

You can sit on your Windows laptop, type one simple command, and Zig will pack up your program so it can run on a Mac, a Linux server, or even a tiny smart-home gadget.

zig build-exe hello.zig -target x86_64-linux

The Standard Toolbox.

Files

Read, write, and organize files on the computer simply.

Math

Tools for complex numbers and high-speed calculations.

Network

Talk to the internet, send data, and build web tools.

Crypto

Secure your data with built-in locks and keys.

Prove It Works.

Smart workers check their work. Zig has a testing tool built right inside. You don't need to download extra software. You write your tests right next to your real code.

zig test math.zig
Testing "addition"...
Test passed.
Testing "subtraction"...
Test passed.
2 passed, 0 failed.

Which Tool is Right for You?

Language Speed Safety Complexity
C Very Fast Low (Dangerous) Simple
C++ Very Fast Low Extremely High
Rust Very Fast Very High High (Hard to learn)
ZIG Very Fast High Simple

Where does Zig live?

Systems

Building the heavy stuff like Operating Systems and Databases.

Embedded

Small chips inside things like keyboards, fridges, or car engines.

Gaming

Game engines that need to run at 60 or 120 frames per second without stopping.

Web Servers

Servers that handle millions of users on the internet very fast.

More than just a language.

Zig is not just a way to write code. It is also a factory that builds code. We call this a "Compiler."

The secret superpower of Zig is that it can build C and C++ code better than the old tools can. Many companies use Zig just to build their old C code, without even writing any new Zig code!

The Build Factory

  • It builds Zig code.
  • It builds C code.
  • It works on Windows, Mac, and Linux.
  • No messy files to set up.

What does it look like?

A very simple program that says "Hello World".

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

pub fn main() !void {
    // This is how you print words to the screen
    std.debug.print("Hello World!\n", .{});
}
Line 1

We bring in a toolbox called "std" (Standard). This toolbox has useful things like printing text.

Line 3

This is the `main` start point. Every program needs a place to start running.

Line 5

We tell the toolbox to print "Hello World!" on the screen. Simple and clear.

You are not alone.

Zig has a growing group of friendly people who love helping beginners. If you get stuck, there is always someone ready to explain it simply.

Discord GitHub ZigLearn

Ready to write fast code?

1

Download

Get the Zig factory (compiler) onto your computer. It is a tiny, single file.

ziglang.org
2

Write

Create a file named `hello.zig`. Write the simple code we showed you above.

3

Run

Open your computer's terminal window and type the command to run it.

zig run hello.zig