Gaaker Go

Golang Named return values

Go’s return values can be named, and they will be treated as variables defined inside the function.

The name of the return value should have a certain meaning, it can be used as a document.

The lone return statement returns the named return value.

The following is a complete code example.

package main

import "fmt"

func split(sum int) (x, y int) {
	x = sum * 4 / 9
	y = sum - x

func main() {

Below is the program output:

7 10
< Named return values Named return values >