Introduction to Zig Programming Language
Learn Zig Programming Language - Introduction
What is Zig?
Zig is a modern, low level and general purpose programming language.
Hello World in Zig
As with any other programming language, let’s start by implementing a simple hello world program in zig.
Note: Install the zig extension for your preferred IDE.
Create a folder called hello_world and then initialize a zig project inside that folder:
mkdir hello_world
cd hello_world
zig init
You’ll see something like this in your terminal:
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
Now, just open this folder in your preferred IDE and let’s start by understanding its project files.
Understanding Project Files
In the root of our project, you can see a src directory and inside that we have two zig files and each of these file is a separate module (a zig module is simply a text file with some zig code in it.)
main.zig- this module is your main module, this is where you main function lives (similar to golang or python). Here, we need to define ourmainfunction and this function will become our entry point of the program.root.zig- if you are building a library instead of an executable program, then delete themain.zigmodule androot.zigwill be your main module for your library.
build.zig - is a build script written in zig. It is used when we call the build command and it contains all the necessary steps to build the project.
build.zig.zon - It contains information about the project and the dependencies, think of it like package.json in javascript projects.
We will learn how to add dependencies later, for now lets just keep it simple
Writing Hello World Program in Zig
Now, lets start writing our hello world program.
The first thing you should do is just delete all the code from main.zig file.
Then write this code:
const std = @import("std");
pub fn main() void {
std.debug.print("Hello, {s}!\\n", .{"World"});
}
Now, let me explain what’s going on:
First, we are importing
std, this gives access to the zig’s standard library. In Zig, to import a module, we use@importsyntax. You can think of it asimportthat we use in python or javascript.Then we are creating a public function called
mainthat returnsvoid. In zig, a function can be public or private. If a function is public, then other modules can import call this public function. If a function is private, then other modules can’t call the function.This
mainfunction uses the standard library to print “Hello, world!”.
Compiling your source code
Now, we got a basic idea of the project structure, so lets now understand how to compile and run a zig program.
To compile a zig program, you can use the build-exe command like this:
zig build-exe src/main.zig
This will create a binary executable in our project root directory. Now, we need to run this executable:
./main
This will print Hello, world! in the terminal.
To compile and execute/run at the same time, use this:
zig run src/main.zig
Ok, lets wrap up for today. My main motive for this post was to give you a brief on Zig programming language. From the next post, we will start learning in detail about variables, functions and everything else. Till then, Goodbye!

