0Pricing
Zig Academy · Lesson

Const Pointers and Alignment

Express read-only access and layout.

Read-Only Access

Often you want to share a value but promise not to change it. A const pointer grants read access while forbidding writes.

The *const T Type

Write a pointer to immutable data as *const T. You can read through it, but assigning to its target is a compile error.

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

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