• Home
  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • React
      • Introduction to React
      • React Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
  • Interactive Training
  • Pricing
  • Navigate
    • Home
    • Reading Grounds
    • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds

Courses

  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React
    • Introduction to React
    • React Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

Introduction to Zig - Lesson 1

Lesson 1 of 28

Hello World

Lesson Progress: 0%

Lesson Progress: 0%
Hello World
Lesson Incomplete
Lesson 1 of 28
Next: Comments →

Zig is a general-purpose programming language that gives you full control over your code. Every Zig program starts by importing the standard library with @import("std") and defining a main function. The pub fn main() void line is the entry point where execution begins. To display text, use std.debug.print which takes a format string and an empty tuple .{}. This lesson will teach you how to write and run your first Zig programs step by step.

Code Example
const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, world!", .{});
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Zig Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • const std = @import("std"); brings in Zig's standard library so you can use its functions.
  • pub fn main() void declares the main function that runs when the program starts.
  • std.debug.print prints text to the terminal for debugging and learning.
  • "Hello, world!\n" is the string to print, and \n moves to a new line.
  • The empty tuple .{} provides no extra values to insert into the format string.
Code Example
const std = @import("std");

pub fn main() void {
    std.debug.print("Hello from Zig!", .{});
    std.debug.print("Welcome to the language.", .{});
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Zig Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can call std.debug.print multiple times to print several lines.
  • Each call to std.debug.print prints one line of text.
  • The program runs top to bottom, so the first message prints before the second.
  • Every Zig program needs a pub fn main() void to start.
Code Example
const std = @import("std");

pub fn main() void {
    const msg = "Hello, world!";
    std.debug.print("{s}", .{msg});
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Zig Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • const msg = "Hello, world!"; stores the message in a constant variable.
  • {s} in the format string is a placeholder for a string value.
  • .{msg} passes the variable msg to fill the placeholder.
  • Using variables makes your code easier to change later.
Code Example
const std = @import("std");

pub fn main() void {
    const name = "Zig";
    const year = 2024;
    std.debug.print("Hello {s} in {d}!", .{ name, year });
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Zig Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can use multiple placeholders like {s} for strings and {d} for numbers.
  • The tuple .{ name, year } provides values in the same order as the placeholders.
  • const declares a variable that cannot change after it is set.
  • Zig uses {s} for strings and {d} for integers in format strings.
Code Example
const std = @import("std");

fn greet() void {
    std.debug.print("Greetings from Zig!", .{});
}

pub fn main() void {
    greet();
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Zig Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A function is defined with fn functionName() void { ... }.
  • greet() is a custom function that prints a message when called.
  • The main function calls greet() to run its code.
  • Functions help you organise code into reusable pieces.
Code Example
const std = @import("std");

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

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Zig Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • std.io.getStdOut().writer() gets a writer for the standard output.
  • The writer.print() method prints formatted text like std.debug.print.
  • catch {} handles any errors that might occur during printing.
  • This is a more advanced way to print that is used in larger Zig programs.

Test Incomplete

What does the line `const std = @import("std");` do in a Zig program?

Question #

1/15

Score

0/0 - 0.0 %