From 87541c0c8bc0969e174c6877a69750445ac1865e Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Sun, 3 Jan 2021 20:34:26 -0500 Subject: Added Ex. 4 arrays --- 04_arrays.zig | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 04_arrays.zig (limited to '04_arrays.zig') diff --git a/04_arrays.zig b/04_arrays.zig new file mode 100644 index 0000000..2e3c208 --- /dev/null +++ b/04_arrays.zig @@ -0,0 +1,31 @@ +// +// Let's learn some array basics. Arrays literals are declared with: +// +// [size]{ values }; +// +// When Zig can infer the size of the array, you can use '_' for the +// size like so: +// +// [_]{ values }; +// +const std = @import("std"); + +pub fn main() void { + const some_primes = [_]u8{ 2, 3, 5, 7, 11, 13, 17, 19 }; + + // Array values are accessed using square bracket '[]' notation. + // + // (Note that when Zig can infer the type (u8 in this case) of a + // value, we don't have to manually specify it.) + // + const first = some_primes[0]; + + // Looks like we need to complete this expression: + const fourth = ???; + + // Use '.len' to get the length of the array: + const length = some_primes.???; + + std.debug.print("First: {}, Fourth: {}, Length: {}\n", + .{first, fourth, length}); +} -- cgit v1.2.3-ZIG