0Pricing
Zig Academy · Lesson

Single-Item Pointers with *T

Point at exactly one value.

Single-Item Pointers with *T is a free Zig Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

A Pointer Points

A pointer holds the address of a value living somewhere else in memory, instead of holding the value itself. 📍

The *T Type

A single-item pointer has the type *T, where T is what it points at. So *i32 means a pointer to one i32 value.

var p: *i32 = undefined;

Take an Address

Use the & operator in front of a variable to get a pointer to it. The result is the address where that value is stored.

var x: i32 = 10;
const p = &x;

One Value Only

A single-item pointer guarantees it refers to exactly one value, not an array. The compiler tracks that for you.

Pointers Have a Size

A pointer is just an address, so its size is the machine word, not the size of T. Pointing at a huge struct still costs one address.

Mutable by Default

A plain *T lets you both read and write the value it points to. You will add const later to make it read-only.

var n: i32 = 1;
const p: *i32 = &n;

Pointers Share, Not Copy

Passing a pointer to a function shares the original value, so changes made through it are visible to the caller.

fn bump(p: *i32) void {
    p.* += 1;
}

Address of a const

Taking &x on a const gives you a *const i32, because Zig will not let you write through a pointer to immutable data.

const x: i32 = 5;
const p = &x;

Pointers Are Never Null

An ordinary Zig pointer can never be null. If a value might be missing you must use an optional pointer like ?*T.

Type Inference Helps

When you write const p = &x, Zig infers the pointer type from x, so you rarely have to spell out *i32 by hand.

var score: u8 = 42;
const p = &score;

Why Use Pointers

Pointers let you modify a value in place and avoid copying large data, which is core to Zig's explicit low-level control.

Quick Check

You want a function to change a caller's variable. What type should the parameter be?

Recap

A single-item pointer *T holds the address of exactly one value, is taken with &, is never null, and lets you share data instead of copying it. 🎯

Frequently asked questions

Is the “Single-Item Pointers with *T” lesson free?

Yes — the full text of “Single-Item Pointers with *T” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “Single-Item Pointers with *T”?

Point at exactly one value. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Single-Item Pointers with *T” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Single-Item Pointers with *T
  2. Dereferencing with ptr.*
  3. Many-Item Pointers [*]T
  4. Const Pointers and Alignment
← Back to Zig Academy