Function declaration
Context
Section titled “Context”Functions in Go are declared with the func keyword, followed by the function name, parameters (with types), and return types (if any). Parameters and return types are mandatory. Go functions can return multiple values.
Example
Section titled “Example”Declare a simple function that adds two integers.
Code example
Section titled “Code example”package main
import "fmt"
func add(a int, b int) int { return a + b}
// Parameters of the same type can be combinedfunc multiply(a, b int) int { return a * b}
func main() { sum := add(5, 3) product := multiply(4, 2) fmt.Println("Sum:", sum) fmt.Println("Product:", product)}Output
Section titled “Output”Sum: 8Product: 8