Hello. It's day 2 of learning Zig and I'm stuck trying to understand a few things.
My background is C and C++.
In Zig, when I declare an array:
var arr: [5]u8 = undefined;
This is sort of the equivalent of this C code:
unsigned char arr[5];
In C, arr would now be a pointer to a block of memory that contains 5 unsigned char's.
But, in Zig, this is not the case? In Zig, what would arr be? And why do I need to do &arr to get the address of the start of the memory block?
It says that an Array in Zig is a type on it's own, and not like a pointer to the start of some memory, like in C. But the only "member" of an Array is it's length, so... where are the contents? &arr is where they are stored I guess, but if so, where is arr.len stored? This is a bit confusing for me so if someone could clarify it would be great.
Regarding Slices and Arrays in Zig, (the language reference has pretty much no text explaining the details of this, just code examples), is the only diference that the length is runtime and not complie time, and they are the same type, or are they different types? Some functions ask for Slices, other ask for whatever &arr returns, and it's all a bit confusing for me, I must be missing something.