diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-01-03 18:55:45 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-01-03 18:55:45 -0500 |
commit | b3f74d9c30b7adc6d5cc971b50b8b8a512fe3448 (patch) | |
tree | 224c8604de622b0f1c1e59533c5ca838206a0784 /03_assignment.zig | |
parent | d618414c9cd144e3d63f2b12df7b512b98df041c (diff) | |
download | ziglings-b3f74d9c30b7adc6d5cc971b50b8b8a512fe3448.tar.gz ziglings-b3f74d9c30b7adc6d5cc971b50b8b8a512fe3448.tar.bz2 ziglings-b3f74d9c30b7adc6d5cc971b50b8b8a512fe3448.tar.xz ziglings-b3f74d9c30b7adc6d5cc971b50b8b8a512fe3448.zip |
Add exercise 3, exercise num param for script
Diffstat (limited to '03_assignment.zig')
-rw-r--r-- | 03_assignment.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/03_assignment.zig b/03_assignment.zig new file mode 100644 index 0000000..6280833 --- /dev/null +++ b/03_assignment.zig @@ -0,0 +1,30 @@ +// +// Oh dear! It seems we got a little carried away making const u8 values. +// * const means constant (cannot be changed) +// * u8 means unsigned (cannot be negative), 8-bit integer +// +// Hint 1: Use 'var' for values that can change. +// Hint 2: Use enough bits to hold the value you want: +// u8 255 +// u16 65,535 +// u32 4,294,967,295 +// Hint 3: Use 'i' (e.g. 'i8', 'i16') for signed integers. +// +const std = @import("std"); + +pub fn main() void { + const n: u8 = 50; + n = n + 5; + + const pi: u8 = 314159; + + const negative_eleven: u8 = -11; + + // There are no errors in the next line, just explanation: + // Perhaps you noticed before that the print function takes two + // parameters. Now it will make more sense: the first parameter + // is a string. The string may contain placeholders '{}', and the + // second parameter is an anonymous struct (data structure) + // with values to be printed in place of the placeholders. + std.debug.print("{} {} {}\n", .{n, pi, negative_eleven}); +} |