Pointers
Astra pointers let you hold a reference to a variable and read or update its value indirectly — even from inside a function. Two built-in functions handle everything: adr() and val().
| Function | Usage | What it does |
|---|---|---|
| adr(x) | p = adr(x) | Returns a pointer (address) to variable x |
| val(p) | val(p) | Reads the current value at the address p points to |
| adr(p, v) | adr(p, 42) | Writes value v to the address p points to |
adr() — Get an Address
Call adr(variable) with one argument to get a pointer to that variable. Store it in another variable to use later.
variable
counter
5
←
pointer
pc
adr(counter)
val() — Read a Value
Call val(pointer) to read the current value of the variable the pointer refers to.
💡
val(p) always reads the current value — if the original variable changes, val(p) reflects that immediately.adr() — Write a Value
Call adr(pointer, newValue) with two arguments to update the variable the pointer points to. This changes the original variable directly.
⚠️
adr(p, value) modifies the original variable in-place — not a copy. Changes are visible everywhere that variable is used.Pointers in Functions
By default, Astra passes values to functions by copy. To let a function modify the caller's variable, pass a pointer and use adr() / val() inside.
Without pointer — copy only
With pointer — updates original
Recursive example — decrement counter
Output:
Common Patterns
Swap two variables
Accumulate into a variable
Conditional update
ℹ️ Pointers in Astra are safe — they always refer to a named variable in the current program. There is no raw memory access or pointer arithmetic.