Functions

A function can take zero or more arguments.

In this example, add takes two parameters of type int.

Notice that the type comes after the variable name.

(For more about why types look the way they do, see the article on Go's declaration syntax.)

functions.go

  1. package main
  2. import "fmt"
  3. func add(x int, y int) int {
  4. return x + y
  5. }
  6. func main() {
  7. fmt.Println(add(42, 13))
  8. }