004_arrays.patch 1.0 KB

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