my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'added expalantion for const pointer' (#428) from pointer into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/428

Chris Boesch (May 22, 2026, 10:27 PM +0200) 8468040a 926fc04d

+18 -2
+16
exercises/040_pointers2.zig
··· 27 27 28 28 std.debug.print("a: {}, b: {}\n", .{ a, b.* }); 29 29 } 30 + // 31 + // A look into the future: 32 + // When you allocate memory, you store the returned address in 33 + // a const var. The pointer itself never changes — it always 34 + // refers to the same allocation — but you can still read and 35 + // write the data it points to. 36 + // 37 + // Example: 38 + // 39 + // const buf = try allocator.alloc(u8, 1024); 40 + // buf[0] = 42; // fine: the *contents* are mutable 41 + // 42 + // Note: 43 + // Passing this pointer to a function is cheap: it's just an address 44 + // copied on the stack. The caller can work with the data without 45 + // needing to know where it came from or how it was allocated.
+2 -2
patches/patches/040_pointers2.patch
··· 1 - --- exercises/040_pointers2.zig 2023-10-03 22:15:22.122241138 +0200 2 - +++ answers/040_pointers2.zig 2023-10-05 20:04:07.022766257 +0200 1 + --- exercises/040_pointers2.zig 2026-05-22 21:57:28.601255748 +0200 2 + +++ answers/040_pointers2.zig 2026-05-22 21:57:27.672235943 +0200 3 3 @@ -23,7 +23,7 @@ 4 4 5 5 pub fn main() void {