September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will present examples of the previous types of functions using the Go code of the functions.go program. The first part of the program contains the expected preamble and the implementation of the unnamedMinMax() function:
package main
import (
"fmt"
)
func unnamedMinMax(x, y int) (int, int) {
if x > y {
min := y
max := x
return min, max
} else {
min := x
max := y
return min, max
}
}
The unnamedMinMax() function is a regular function that gets two integer numbers as input, named x and y, respectively. It returns two integer numbers as output using a return statement.
The next part of functions.go defines another function but this time with named returned values, which are called min and max:
func minMax(x, ...
Read now
Unlock full access