aboutsummaryrefslogtreecommitdiff
path: root/19_functions2.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-01-22 17:42:03 -0500
committerDave Gauer <dave@ratfactor.com>2021-01-22 17:42:03 -0500
commit08ec029f20381580ebe76ad8bd3feca2e5cd262a (patch)
tree818a56fd583bab292fc61c5203762ec56a31f208 /19_functions2.zig
parenta361b90a7562bcc5a62f863b42ae6a33aaa4b812 (diff)
downloadziglings-08ec029f20381580ebe76ad8bd3feca2e5cd262a.tar.gz
ziglings-08ec029f20381580ebe76ad8bd3feca2e5cd262a.tar.bz2
ziglings-08ec029f20381580ebe76ad8bd3feca2e5cd262a.tar.xz
ziglings-08ec029f20381580ebe76ad8bd3feca2e5cd262a.zip
Added ex 19,20 functions and pop quiz
Diffstat (limited to '19_functions2.zig')
-rw-r--r--19_functions2.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/19_functions2.zig b/19_functions2.zig
new file mode 100644
index 0000000..68cc67b
--- /dev/null
+++ b/19_functions2.zig
@@ -0,0 +1,28 @@
+//
+// Now let's use a function that takes a parameter.
+//
+const std = @import( "std" );
+
+pub fn main() void {
+ std.debug.print("Powers of two: {} {} {} {}\n", .{
+ twoToThe(1),
+ twoToThe(2),
+ twoToThe(3),
+ twoToThe(4),
+ });
+}
+
+//
+// Oops! We seem to have forgotten something here. Function
+// parameters look like this:
+//
+// fn myFunction( number: u8, is_lucky: bool ) {
+// ...
+// }
+//
+// As you can see, we declare the type of the parameter, just
+// like we declare the types of variables, with a colon ":".
+//
+fn twoToThe(???) u32 {
+ return std.math.pow(u32, 2, my_number);
+}