Many-Item Pointers [*]T
Address a run of elements.
Many-Item Pointers [*]T is a free Zig Academy lesson on CoddyKit — lesson 3 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.
Pointing at a Run
Sometimes a pointer addresses not one value but the start of a sequence of values laid out in memory. 🧱
The [*]T Type
A many-item pointer is written [*]T. The star inside the brackets means it points at an unknown number of T values in a row.
var run: [*]u8 = undefined;No Length Attached
Unlike a slice, a many-item pointer carries no length. You alone must know how many elements are safe to touch.
Index Like an Array
You can index a many-item pointer with brackets, so run[2] reaches the third element by stepping forward in memory.
const third = run[2];Pointer Arithmetic
Adding to a many-item pointer moves it by whole elements, so run + 1 points one T further along, not one byte.
const next = run + 1;Single vs Many
A *T points at exactly one value and cannot be indexed; a [*]T points at many and supports indexing and arithmetic.
Where They Come From
Many-item pointers often appear when talking to C, which passes a bare pointer to a buffer with the length tracked separately.
No Bounds Checks
Because the length is unknown, indexing a many-item pointer is not bounds-checked. Reading too far is undefined behavior.
Prefer Slices
When you control the code, a slice []T is safer because it bundles the length. Reach for [*]T mainly at C boundaries.
From Pointer to Slice
Once you know the count, attach a length with ptr[0..n] to turn a many-item pointer into a safe, bounds-checked slice.
const view = run[0..n];Sentinel Variants Exist
Zig also has sentinel-terminated forms like [*:0]u8, a pointer whose run ends at a known value such as a zero byte.
var cstr: [*:0]const u8 = "hi";Quick Check
Compare a slice []T with a many-item pointer [*]T. What does the many-item pointer lack?
Recap
A many-item pointer [*]T addresses a run of values, supports indexing and arithmetic, has no length, and is best converted to a slice when possible. 🎯
Frequently asked questions
Is the “Many-Item Pointers [*]T” lesson free?
Yes — the full text of “Many-Item Pointers [*]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 “Many-Item Pointers [*]T”?
Address a run of elements. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Many-Item Pointers [*]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
- Single-Item Pointers with *T
- Dereferencing with ptr.*
- Many-Item Pointers [*]T
- Const Pointers and Alignment