SultanC
  1. Home
  2. Examples
  3. Memory

Heap values with `box`, and raw pointers that need an `unsafe` block

memory/box_and_pointers.sn
// Heap values with `box`, and raw pointers that need an `unsafe` block.
import std.io.println;
import std.text.number;

def main(): int {
    let boxed: box int = box 40;
    let total: int = *boxed + 2;
    println(int_to_text(total));

    let counter: mutable int = 10;
    let pointer: *mutable int = &mutable counter;
    unsafe {
        *pointer := *pointer * 3;
    }
    println(int_to_text(counter));
    return 0;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/memory/box_and_pointers.sn

Or compile it to an executable:

./build/sultanc examples/en/memory/box_and_pointers.sn -o build/example && ./build/example

Source on GitHub   All examples