"Define function"
Directly on the chestnut, go language defines the function:
func add(a int, b int) int {
return a + b
}
At a glance, not too accustomed to the name of the go language, type why write to the back?
"Multiple Return Values"
The Go function can also return multiple values:
func add(a int, b int)(int , int){
return a, a + b
}
"Named Return value"
func add(a int, b int) (c int) {
c = a + b
return
}
According to the internet, the named return value is, as in the above code. The function automatically defines C, and it automatically returns C.
"Multiple Identical types"
If the function parameter has more than one type, then one is written, and the named return value applies.
func add(a, b int) (c int) {
c = a + b
return
}
"White space character"
The function returns multiple parameters, and we only need to use one, and the other parameters do not need to use the whitespace character ' _ ', an underscore.
package main
import (
"fmt"
)
func add(a, b int) (c, d int) {
c = a + b
d = a * b
return
}
func main() {
c, _ := add(3, 4)
fmt.Printf("c = %v\n", c)
}
5. Go function