Web Development

Functions are blocks of code that to execute. This is the Go Language syntax for functions

package main

import "fmt"

func add(x, y int) int {
  return x + y
}

func multiply_by_two(z int) int {
  return z * 2
}

func main() {
  first := 100
  second := 200
  third := 300

  added := add(first, second)
  fmt.Println("", added)

  multiplied := multiply_by_two(third)
  fmt.Println("", multiplied)
}

Output

$ go run func.go 
 300
 600

Notes

  • when parameters have the same data type, you can omit the its declaration and put it at the end
  • you need to specify the return value of the function after the parenthesis