1const expectEqual = @import("std").testing.expectEqual;
2
3test "optional pointers" {
4 // Pointers cannot be null. If you want a null pointer, use the optional
5 // prefix `?` to make the pointer type optional.
6 var ptr: ?*i32 = null;
7
8 var x: i32 = 1;
9 ptr = &x;
10
11 try expectEqual(1, ptr.?.*);
12
13 // Optional pointers are the same size as normal pointers, because pointer
14 // value 0 is used as the null value.
15 try expectEqual(@sizeOf(?*i32), @sizeOf(*i32));
16}
17
18// test