19_functions2.zig 625 B

12345678910111213141516171819202122232425262728
  1. //
  2. // Now let's use a function that takes a parameter.
  3. //
  4. const std = @import( "std" );
  5. pub fn main() void {
  6. std.debug.print("Powers of two: {} {} {} {}\n", .{
  7. twoToThe(1),
  8. twoToThe(2),
  9. twoToThe(3),
  10. twoToThe(4),
  11. });
  12. }
  13. //
  14. // Oops! We seem to have forgotten something here. Function
  15. // parameters look like this:
  16. //
  17. // fn myFunction( number: u8, is_lucky: bool ) {
  18. // ...
  19. // }
  20. //
  21. // As you can see, we declare the type of the parameter, just
  22. // like we declare the types of variables, with a colon ":".
  23. //
  24. fn twoToThe(???) u32 {
  25. return std.math.pow(u32, 2, my_number);
  26. }