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
- Single-Item Pointers with *T
- Dereferencing with ptr.*
- Many-Item Pointers [*]T
- Const Pointers and Alignment