• 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.

Zig Developer -

Lesson 1 of 85

Lesson Progress: 0%

Lesson Progress: 0%
Lesson Incomplete
Lesson 1 of 85
Next: Address Of Operator →

A pointer holds the memory address of a value. In Zig, pointers are explicit and always refer to a valid value at runtime. Every pointer has a type written as *T for a pointer to a single item of type T. Zig does not allow null pointers by default, which eliminates a whole class of bugs. Pointers can point to mutable or immutable data depending on whether you use *const T or *T. Understanding pointers is essential for working with memory, passing data efficiently, and interfacing with C code.

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

pub fn main() void {
    const x: i32 = 42;
    const ptr: *const i32 = &x;

    std.debug.print("{d}", .{ptr.*});
}

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
  • The & operator takes the address of a variable and produces a pointer.
  • *const i32 is the type of a pointer to a read-only i32.
  • Use p.* (dot-star) to access the value that the pointer points to.
  • Pointers in Zig always point to valid, initialized memory.
Code Example
const std = @import("std");

pub fn main() void {
    const x: i32 = 7;
    const p: *const i32 = &x;
    std.debug.print("{any}", .{p == &x});
}

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
  • Every pointer type carries the type of the value it points to.
  • *const u8 and *const i16 are different types.
  • You can take the address of values with any type.
  • Dereferencing preserves the original type of the pointed-to value.
Code Example
const std = @import("std");

pub fn main() void {
    const val: f64 = 3.14;
    const p: *const f64 = &val;
    std.debug.print("{d}", .{p.*});
}

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 pointer to an array has type *const [N]T.
  • &arr produces a pointer to the entire array, not just the first element.
  • Use p.*[index] to access an element through the pointer.
  • The pointer carries the full array length in its type.
Code Example
const std = @import("std");

pub fn main() void {
    const a: u8 = 10;
    const b: u8 = 20;
    const pa: *const u8 = &a;
    const pb: *const u8 = &b;
    std.debug.print("{d}", .{pa.* + pb.*});
}

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
  • Two pointers to different variables always have different addresses.
  • Even if the values are equal, &x and &y are distinct pointers.
  • Dereferencing each pointer gives you the value stored at that address.
  • Pointer equality compares addresses, not the pointed-to values.
Code Example
const std = @import("std");

pub fn main() void {
    const msg: []const u8 = "hello";
    const p: *const []const u8 = &msg;
    std.debug.print("{s}", .{p.*});
}

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 mutable pointer *T lets you modify the value it points to.
  • Assigning to p.* changes the underlying variable.
  • The variable val reflects the change because the pointer shares the same memory.
  • Pointers provide a way to update values without returning them from functions.
Code Example
const std = @import("std");

pub fn main() void {
    const x: bool = true;
    const p: *const bool = &x;
    std.debug.print("{any}", .{p.*});
}

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 create a pointer to another pointer, giving a double pointer *const *const T.
  • Dereference twice, pp.*.*, to reach the original value.
  • Pointers to pointers are useful for modifying a pointer variable from a function.
  • Each level of indirection adds one .* dereference.

Test Incomplete

What does the & operator do in Zig?

Question #

1/15

Score

0/0 - 0.0 %