Fundamentals5 / 9
Up next

Arrays

const std = @import("std");

pub fn main() void {
    // [_] infers the length from the initializer
    const primes = [_]u32{ 2, 3, 5, 7, 11 };
    // a repeated-value array
    const zeros = [_]u8{0} ** 4;
    // for can also yield the index with a second capture
    for (primes, 0..) |p, i| {
        std.debug.print("{d}:{d} ", .{ i, p });
    }
    std.debug.print("\nlen {d}, zeros {any}\n", .{ primes.len, zeros });
}
What you're solving

fixed-size arrays and index-with-for