function_parameter.go 289 B

1234567891011121314151617181920
  1. // function_parameter.go
  2. package main
  3. import (
  4. "fmt"
  5. )
  6. func main() {
  7. callback(1, Add)
  8. }
  9. func Add(a, b int) {
  10. fmt.Printf("The sum of %d and %d is: %d\n", a, b, a+b)
  11. }
  12. func callback(y int, f func(int, int)) {
  13. f(y, 2) // this becomes Add(1, 2)
  14. }
  15. // Output: The sum of 1 and 2 is: 3