On Friday, 9 February 2024 at 02:55:48 UTC, Gary Chike wrote:
On Friday, 9 February 2024 at 02:13:04 UTC, Gary Chike wrote:

I spoke too soon, it appears Zig's default return type for its `len()` function is: `usize' - similar to Rust.

```rust
const std = @import("std");

pub fn main() !void {
    const something = [_]u8{ 'a', 'b', 'c' };

    std.debug.print("len: {d}\n", .{something.len}); // Len: 3
    const len_type = @typeName(@TypeOf(something.len));
std.debug.print("len type: {s}\n", .{len_type}); // len type: usize

    var i: i32 = -1;
    while (i <= @intCast(i32, something.len)) : (i += 1) {
        std.debug.print("i: {d}\n", .{i});
    }
}

```
Output:
```
len: 3
len type: usize
i: -1
i: 0
i: 1
i: 2
i: 3
```


Reply via email to