i32 is Zig’s signed 32-bit integer type. Annotate a value such as 42 when its type is not clear from context; i32 also serves as a general-purpose function return type. In Fibonacci’s base cases, the compiler infers the return literals as i32. section 2.1.1 section 2.1.3
Listing 2.2 Recursive fibonacci
const std = @import("std");
fn fibonacci(n: usize) i32 { // #1
// #2
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
}
return fibonacci(n - 1) + fibonacci(n - 2); // #3
}
pub fn main() void {
// #4
const first = fibonacci(1);
const second = fibonacci(2);
const third = fibonacci(3);
const fourth = fibonacci(4);
std.debug.print("{} {} {} {}\n", .{ first, second, third, fourth });
}
See i32 used as the recursive Fibonacci function’s return type. section 2.1.3
Overflow in Fibonacci
Computing a Fibonacci value too large for i32 can trigger a runtime panic; n = 47 is suggested as a test. section 2.1.3

