Introduction
Return values let a function send back a result after it finishes its work. This helps you reuse the result elsewhere in your program.
func functionName(parameters) returnType {
// code
return value
}func add(a int, b int) int { return a + b }
func swap(x, y string) (string, string) {
return y, x
}func greet(name string) string {
return "Hello, " + name
}package main import "fmt" func multiply(a int, b int) int { return a * b } func main() { result := multiply(4, 5) fmt.Println("4 times 5 is", result) }
func multiply(a, b int) int {
return a * b
}
func main() {
result := multiply(3, 4)
fmt.Println(result)
}func divide(a, b int) (int, int) {
return a / b
}Pass the test and this pattern moves unknown