Pointers in AngelScript

We’ll show how pointers work in contrast to values with 2 functions: `zeroval` and `zeroptr`. `zeroval` has an `int` parameter, so arguments will be passed to it by value. `zeroval` will get a copy of `ival` distinct from the one in the calling function.

```angelscript
void zeroval(int ival) {
    ival = 0;
}

zeroptr in contrast has an int& parameter, meaning that it takes an int reference. The *iptr code in the function body then dereferences the pointer from its memory address to the current value at that address. Assigning a value to a dereferenced pointer changes the value at the referenced address.

void zeroptr(int& iptr) {
    iptr = 0;
}

Here’s the main function to demonstrate the usage of the above functions:

void main() {
    int i = 1;
    println("initial: " + i);

    zeroval(i);
    println("zeroval: " + i);

    zeroptr(i);
    println("zeroptr: " + i);

    println("pointer: " + PVOID(@i));
}

zeroval doesn’t change the i in main, but zeroptr does because it has a reference to the memory address for that variable.

When run, the output will be:

initial: 1
zeroval: 1
zeroptr: 0
pointer: 0x<address>

Now that we understand how basic pointer operations work, let’s delve deeper into the language.