diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-05-22 22:27:15 +0200 |
|---|---|---|
| committer | Chris Boesch <chrboesch@noreply.codeberg.org> | 2026-05-22 22:27:15 +0200 |
| commit | 8468040a8e8bc48688845bcaea010272da1df446 (patch) | |
| tree | 6f32cdd09d64effb2841d84b7c3b039cb5db7451 | |
| parent | 926fc04d81c62832604c5ebb6bed1f3b01d6189e (diff) | |
| parent | 1d965491c107489b2fcb1d9e304ad7e71b9d391e (diff) | |
Merge pull request 'added expalantion for const pointer' (#428) from pointer into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/428
| -rw-r--r-- | exercises/040_pointers2.zig | 16 | ||||
| -rw-r--r-- | patches/patches/040_pointers2.patch | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/exercises/040_pointers2.zig b/exercises/040_pointers2.zig index a4852f6..e220336 100644 --- a/exercises/040_pointers2.zig +++ b/exercises/040_pointers2.zig @@ -27,3 +27,19 @@ pub fn main() void { std.debug.print("a: {}, b: {}\n", .{ a, b.* }); } +// +// A look into the future: +// When you allocate memory, you store the returned address in +// a const var. The pointer itself never changes — it always +// refers to the same allocation — but you can still read and +// write the data it points to. +// +// Example: +// +// const buf = try allocator.alloc(u8, 1024); +// buf[0] = 42; // fine: the *contents* are mutable +// +// Note: +// Passing this pointer to a function is cheap: it's just an address +// copied on the stack. The caller can work with the data without +// needing to know where it came from or how it was allocated. diff --git a/patches/patches/040_pointers2.patch b/patches/patches/040_pointers2.patch index acdd619..a8ce293 100644 --- a/patches/patches/040_pointers2.patch +++ b/patches/patches/040_pointers2.patch @@ -1,5 +1,5 @@ ---- exercises/040_pointers2.zig 2023-10-03 22:15:22.122241138 +0200 -+++ answers/040_pointers2.zig 2023-10-05 20:04:07.022766257 +0200 +--- exercises/040_pointers2.zig 2026-05-22 21:57:28.601255748 +0200 ++++ answers/040_pointers2.zig 2026-05-22 21:57:27.672235943 +0200 @@ -23,7 +23,7 @@ pub fn main() void { |
