4. What does `for (items, 0..) |item, i|` do?
- Iterates items twice
- Declares a range of zeros
- Iterates items together with an index starting at 0
- It is invalid syntax
जवाब देखें
जवाब: Iterates items together with an index starting at 0
Multi-object for loops iterate several sequences in lockstep, here items and an index range.
पाठ: if, while, for, switch and Labelled Blocks
5. How should you compare the contents of two strings in Zig?
- With ==
- With std.mem.eql(u8, a, b)
- With strcmp
- They cannot be compared
जवाब देखें
जवाब: With std.mem.eql(u8, a, b)
Slices are pointer and length; std.mem.eql compares their bytes.
पाठ: Arrays, Slices and Strings