Read three characters, compute the sum, print it.
'3' - '0' is 3 because ASCII digits are contiguous. But Zig never converts between types implicitly, and input[0] is a u8 -- subtracting one u8 from another would panic if it ever went below zero. We widen to i64 first: @as(i64, input[0]) - '0'.
For now, the input has no spaces. "3+4", not "3 + 4". Whitespace handling comes much later.
Fill in the three // YOU lines.
pub fn main() void {
const input: [:0]const u8 = "3+4";
// YOU: const a: i64 = ...
// YOU: const b: i64 = ...
// YOU: const result: i64 = ...
printString("interpreter result for ");
printString(input);
printString(" : ");
printNumber(result);
printChar('\n');
}
const a: i64 = @as(i64, input[0]) - '0';
const b: i64 = @as(i64, input[2]) - '0';
const result: i64 = a + b;
We're ignoring input[1]. Hardcoded + for now.
In Zig, strings are arrays of bytes. The :0 in [:0]const u8 says "ends with a zero byte" -- a sentinel we'll use as our end-of-input marker later. Don't sweat the exact punctuation; just remember the strings end with a zero.