functions.go 515 B

1234567891011121314151617181920212223242526272829
  1. // Functions:
  2. // A function can take zero or more arguments
  3. package examples
  4. import "fmt"
  5. // Default add function values
  6. const (
  7. X = 5
  8. Y = 7
  9. )
  10. // This function takes two parameters of type int
  11. // (and returns an int) notice that the type comes
  12. // after the variable name.
  13. //
  14. // This could also be written:
  15. // func add(x, y int) int
  16. // if parameters are the same type
  17. func add(x int, y int) int {
  18. return x + y
  19. }
  20. func Functions() int {
  21. ans := add(X, Y)
  22. fmt.Printf("%d + %d => %d\n", X, Y, ans)
  23. return ans
  24. }