Files
sx/examples/26-pointers.sx
2026-02-14 14:52:39 +02:00

29 lines
509 B
Plaintext

#import "modules/std.sx";
Vec2 :: struct { x, y: f32; }
set_x :: (p: *Vec2, val: f32) {
p.x = val;
}
main :: () {
v := Vec2.{ 1.0, 2.0 };
print("before: {}\n", v);
set_x(@v, 99.0);
print("after: {}\n", v);
ptr := @v;
copy := ptr.*;
print("copy: {}\n", copy);
// null pointer
np : *Vec2 = null;
// many-pointer indexing
arr : [5]s32 = .[10, 20, 30, 40, 50];
mp : [*]s32 = @arr[0];
print("mp[0] = {}\n", mp[0]);
print("mp[2] = {}\n", mp[2]);
}