018_functions.zig 850 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Functions! We've already created lots of functions called 'main()'. Now let's
  3. // do something different:
  4. //
  5. // fn foo(n: u8) u8 {
  6. // return n + 1;
  7. // }
  8. //
  9. // The foo() function above takes a number 'n' and returns a number that is
  10. // larger by one.
  11. //
  12. // Note the input parameter 'n' and return types are both u8.
  13. //
  14. const std = @import("std");
  15. pub fn main() void {
  16. // The new function deepThought() should return the number 42. See below.
  17. const answer: u8 = deepThought();
  18. std.debug.print("Answer to the Ultimate Question: {}\n", .{answer});
  19. }
  20. // Please define the deepThought() function below.
  21. //
  22. // We're just missing a couple things. One thing we're NOT missing is the
  23. // keyword "pub", which is not needed here. Can you guess why?
  24. //
  25. ??? deepThought() ??? {
  26. return 42; // Number courtesy Douglas Adams
  27. }