Skip to content

Pointers

Run has two pointer types that control access to the pointed-to value.

&T is a read/write pointer. It allows both reading and modifying the pointed-to value.

package main
use "fmt"
fun increment(p: &int) {
p.* = p.* + 1
}
pub fun main() {
var x int = 10
increment(&x)
fmt.println(x) // 11
}

@T is a read-only pointer. It allows reading but not modifying the pointed-to value.

fun print_value(p: @int) {
fmt.println(p.*) // ok: reading
// p.* = 42 // error: cannot write through read-only pointer
}

This distinction is enforced at compile time and helps express intent clearly — use @T when a function only needs to observe a value, and &T when it needs to modify it.