aboutsummaryrefslogtreecommitdiff
path: root/exercises/008_quiz.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-06-14 11:26:04 -0400
committerDave Gauer <dave@ratfactor.com>2021-06-14 11:26:04 -0400
commit621d72db56dfcf7427b4bac238493afd6d37f780 (patch)
tree4e9a726fe637fa8ed573aad5a36e9beeb3a9a8e6 /exercises/008_quiz.zig
parentf07615ef96564beb7b577ff207c418096651e548 (diff)
downloadziglings-621d72db56dfcf7427b4bac238493afd6d37f780.tar.gz
ziglings-621d72db56dfcf7427b4bac238493afd6d37f780.tar.bz2
ziglings-621d72db56dfcf7427b4bac238493afd6d37f780.tar.xz
ziglings-621d72db56dfcf7427b4bac238493afd6d37f780.zip
New usize explanation 008, etc.
Diffstat (limited to 'exercises/008_quiz.zig')
-rw-r--r--exercises/008_quiz.zig17
1 files changed, 13 insertions, 4 deletions
diff --git a/exercises/008_quiz.zig b/exercises/008_quiz.zig
index 309a8ae..5a81fb2 100644
--- a/exercises/008_quiz.zig
+++ b/exercises/008_quiz.zig
@@ -1,7 +1,7 @@
//
// Quiz time! Let's see if you can fix this whole program.
//
-// This is meant to be challenging.
+// You'll have to think about this one a bit.
//
// Let the compiler tell you what's wrong.
//
@@ -13,14 +13,23 @@ pub fn main() void {
// What is this nonsense? :-)
const letters = "YZhifg";
+ // Note: usize is an unsigned integer type used for...sizes.
+ // The exact size of usize depends on the target CPU
+ // architecture. We could have used a u8 here, but usize is
+ // the idiomatic type to use for array indexing.
+ //
+ // There IS a problem on this line, but 'usize' isn't it.
const x: usize = 1;
- // This is something you haven't seen before: declaring an array
- // without putting anything in it. There is no error here:
+ // Note: When you want to declare memory (an array in this
+ // case) without putting anything in it, you can set it to
+ // 'undefined'. There is no problem on this line.
var lang: [3]u8 = undefined;
// The following lines attempt to put 'Z', 'i', and 'g' into the
- // 'lang' array we just created.
+ // 'lang' array we just created by indexing the array
+ // 'letters' with the variable 'x'. As you can see above, x=1
+ // to begin with.
lang[0] = letters[x];
x = 3;