ziglings/patches/patches/004_arrays.patch

25 lines
1 KiB
Diff

--- exercises/004_arrays.zig 2023-10-03 22:15:22.122241138 +0200
+++ answers/004_arrays.zig 2023-10-05 20:04:06.859429866 +0200
@@ -27,7 +27,7 @@
// (Problem 1)
// This "const" is going to cause a problem later - can you see what it is?
// How do we fix it?
- const some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
+ var some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
// Individual values can be set with '[]' notation.
// Example: This line changes the first prime to 2 (which is correct):
@@ -40,11 +40,11 @@
// (Problem 2)
// Looks like we need to complete this expression. Use the example
// above to set "fourth" to the fourth element of the some_primes array:
- const fourth = some_primes[???];
+ const fourth = some_primes[3];
// (Problem 3)
// Use the len property to get the length of the array:
- const length = some_primes.???;
+ const length = some_primes.len;
std.debug.print("First: {}, Fourth: {}, Length: {}\n", .{
first, fourth, length,