18_functions.zig 719 B

1234567891011121314151617181920212223
  1. //
  2. // Functions! FUNctions! FUN!
  3. //
  4. const std = @import("std");
  5. pub fn main() void {
  6. // The new function deepThought() should return the number 42. See below.
  7. const answer: u8 = deepThought();
  8. std.debug.print("Answer to the Ultimate Question: {}\n", .{answer});
  9. }
  10. //
  11. // We're just missing a couple things here. One thing we're NOT missing is the
  12. // keyword "pub", which is not needed here. Can you guess why?
  13. //
  14. // Functions need to specify the type of value they return. The main() function
  15. // above has a special return type "void", which means it returns nothing. This
  16. // function returns something. What might that be?
  17. //
  18. ??? deepThought() ??? {
  19. return 42; // Number courtesy Douglas Adams
  20. }