diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-01-04 18:40:34 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-01-04 18:40:34 -0500 |
commit | faa49abb068adca4ecc6c00dfe72d0674a763217 (patch) | |
tree | 3c539d0715b3d859c6423dc206320f92bc9157ea /05_arrays2.zig | |
parent | 87541c0c8bc0969e174c6877a69750445ac1865e (diff) | |
download | ziglings-faa49abb068adca4ecc6c00dfe72d0674a763217.tar.gz ziglings-faa49abb068adca4ecc6c00dfe72d0674a763217.tar.bz2 ziglings-faa49abb068adca4ecc6c00dfe72d0674a763217.tar.xz ziglings-faa49abb068adca4ecc6c00dfe72d0674a763217.zip |
Added Ex. 5, array ops
Diffstat (limited to '05_arrays2.zig')
-rw-r--r-- | 05_arrays2.zig | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/05_arrays2.zig b/05_arrays2.zig new file mode 100644 index 0000000..c021096 --- /dev/null +++ b/05_arrays2.zig @@ -0,0 +1,40 @@ +// +// Zig has some fun array operators. +// +// You can use '++' to concatenate two arrays: +// const a = [_]u8{ 1,2 }; +// const b = [_]u8{ 3,4 }; +// const c = a ++ b ++ [_]u8{ 5 }; // 1,2,3,4,5 +// +// You can use '**' to repeat an array: +// const d = [_]u8{ 1,2,3 } ** 2; // 1,2,3,1,2,3 +// +const std = @import("std"); + +pub fn main() void { + const le = [_]u8{ 1, 3 }; + const et = [_]u8{ 3, 7 }; + + // I want this to contain digits: 1 3 3 7 + const leet = ???; + + // I want this to contain digits: 1 0 0 1 1 0 0 1 1 0 0 1 + const bit_pattern = [_]u8{ ??? } ** 3; + + + // We could print these arrays with leet[0], leet[1],...but let's + // have a little preview of Zig 'for' loops instead! + std.debug.print("LEET: ", .{}); + + for (leet) |*n| { + std.debug.print("{}", .{n.*}); + } + + std.debug.print(", Bits: ", .{}); + + for (bit_pattern) |*n| { + std.debug.print("{}", .{n.*}); + } + + std.debug.print("\n", .{}); +} |