forked from fox-archives/volant
-
Notifications
You must be signed in to change notification settings - Fork 4
Pointers
Apoorv Singal edited this page Aug 30, 2020
·
2 revisions
Pointers are variables that store the memory address of a value.
* type
is the type for a pointer that stores the memory address of a value of type type
.
The memory address of value is accessed using the &
operator. For example,
var: i32 = 0;
ptr := &var; // ptr holds the memory address of var
The value at a memory address is accessed using the *
operator. For example,
var := 0; // create a i32 of value 0
ptr := &var; // create a pointer to var
var2 := *ptr; // create var2 of value ptr points to
Pointers are numbers, so all number operations are valid on pointers. For example, *(ptr + x)
gives the value stored at ptr+x
memory address.
See heap for more on pointers.