mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 06:03:09 -05:00
Improved the explanation about passing arguments and added an example.
This commit is contained in:
parent
e3877321b6
commit
9844123dd1
2 changed files with 17 additions and 6 deletions
|
@ -141,9 +141,20 @@ pub fn main() void {
|
||||||
//
|
//
|
||||||
// Moving along...
|
// Moving along...
|
||||||
//
|
//
|
||||||
// Passing arguments to functions is pretty much exactly like
|
// When arguments are passed to a function,
|
||||||
// making an assignment to a const (since Zig enforces that ALL
|
// they are ALWAYS passed as constants within the function,
|
||||||
// function parameters are const).
|
// regardless of how they were declared in the calling function.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// fn foo(arg: u8) void {
|
||||||
|
// arg = 42; // Error, 'arg' is const!
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fn bar() void {
|
||||||
|
// var arg: u8 = 12;
|
||||||
|
// foo(arg);
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// Knowing this, see if you can make levelUp() work as expected -
|
// Knowing this, see if you can make levelUp() work as expected -
|
||||||
// it should add the specified amount to the supplied character's
|
// it should add the specified amount to the supplied character's
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--- exercises/051_values.zig 2023-10-03 22:15:22.122241138 +0200
|
--- exercises/051_values.zig 2024-03-14 23:25:42.695020607 +0100
|
||||||
+++ answers/051_values.zig 2023-10-05 20:04:07.072767194 +0200
|
+++ answers/051_values.zig 2024-03-14 23:28:34.525109174 +0100
|
||||||
@@ -87,7 +87,7 @@
|
@@ -87,7 +87,7 @@
|
||||||
// Let's assign the std.debug.print function to a const named
|
// Let's assign the std.debug.print function to a const named
|
||||||
// "print" so that we can use this new name later!
|
// "print" so that we can use this new name later!
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
// Now let's look at assigning and pointing to values in Zig.
|
// Now let's look at assigning and pointing to values in Zig.
|
||||||
//
|
//
|
||||||
@@ -152,13 +152,13 @@
|
@@ -163,13 +163,13 @@
|
||||||
print("XP before:{}, ", .{glorp.experience});
|
print("XP before:{}, ", .{glorp.experience});
|
||||||
|
|
||||||
// Fix 1 of 2 goes here:
|
// Fix 1 of 2 goes here:
|
||||||
|
|
Loading…
Reference in a new issue