zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

test_optional_pointer.zig (479B) - Raw


      1 const expect = @import("std").testing.expect;
      2 
      3 test "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 expect(ptr.?.* == 1);
     12 
     13     // Optional pointers are the same size as normal pointers, because pointer
     14     // value 0 is used as the null value.
     15     try expect(@sizeOf(?*i32) == @sizeOf(*i32));
     16 }
     17 
     18 // test