05_arrays2.zig 962 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Zig has some fun array operators.
  3. //
  4. // You can use '++' to concatenate two arrays:
  5. // const a = [_]u8{ 1,2 };
  6. // const b = [_]u8{ 3,4 };
  7. // const c = a ++ b ++ [_]u8{ 5 }; // 1,2,3,4,5
  8. //
  9. // You can use '**' to repeat an array:
  10. // const d = [_]u8{ 1,2,3 } ** 2; // 1,2,3,1,2,3
  11. //
  12. const std = @import("std");
  13. pub fn main() void {
  14. const le = [_]u8{ 1, 3 };
  15. const et = [_]u8{ 3, 7 };
  16. // I want this to contain digits: 1 3 3 7
  17. const leet = ???;
  18. // I want this to contain digits: 1 0 0 1 1 0 0 1 1 0 0 1
  19. const bit_pattern = [_]u8{ ??? } ** 3;
  20. // We could print these arrays with leet[0], leet[1],...but let's
  21. // have a little preview of Zig 'for' loops instead!
  22. std.debug.print("LEET: ", .{});
  23. for (leet) |*n| {
  24. std.debug.print("{}", .{n.*});
  25. }
  26. std.debug.print(", Bits: ", .{});
  27. for (bit_pattern) |*n| {
  28. std.debug.print("{}", .{n.*});
  29. }
  30. std.debug.print("\n", .{});
  31. }