Golang Functions Returning Multiple Values
Functions in Golang can return multiple values, which is a helpful feature in many practical scenarios.
This example declares a function with two return values and calls it from a main function.
Example
package main
import "fmt"
func rectangle(l int, b int) (area int, parameter int) {
parameter = 2 * (l + b)
area = l * b
return // Return statement without specify variable name
}
func main() {
var a, p int
a, p = rectangle(20, 30)
fmt.Println("Area:", a)
fmt.Println("Parameter:", p)
}
Most Helpful This Week
What is Function in Golang
Naming Conventions for Golang Functions
User Defined Function Types in Golang
Simple function with parameters in Golang
Closures Functions in Golang
Golang Passing Address to a Function
Creating a Function in Golang
Simple function with return value in Golang
Higher Order Functions in Golang
The return values of a function can be named in Golang
Anonymous Functions in Golang