Questions about pointers: I'm learning a bit of Zig and have never used pointers...
💙🩷💜 Brett [backup account] @brettm@swarm.coiloptic.org
Questions about pointers:
I'm learning a bit of Zig and have never used pointers before (I do understand the general concept of how to use them, that they point to address etc).
afaik using pointers is faster than operating on/ looking up the variables themselves?
My main confusion (using example below) is, why dereference the pointer with 'ptr.*' in the 3rd line? Why not just plug in the address directly with '&num'? Is that for performance too? Otherwise the code seems convoluted for no reason.
var num: u8 = 12;
const ptr: *u8 = #
std.testing.expectEqual(ptr.*, num);
#ziglang
I'm learning a bit of Zig and have never used pointers before (I do understand the general concept of how to use them, that they point to address etc).
afaik using pointers is faster than operating on/ looking up the variables themselves?
My main confusion (using example below) is, why dereference the pointer with 'ptr.*' in the 3rd line? Why not just plug in the address directly with '&num'? Is that for performance too? Otherwise the code seems convoluted for no reason.
var num: u8 = 12;
const ptr: *u8 = #
std.testing.expectEqual(ptr.*, num);
#ziglang