Gaaker Go

Golang Multiple return values

Functions can return any number of return values.

(int, int)
This function returns 2 results of type int.

When calling a function, we can use double assignment to receive these two different return values.

a, b := plus(1,3)

The following is a complete code example.

package main

import "fmt"

func plus(a int, b int) (int, int) {
	return a + 1, b + 1

func main() {
    a, b := plus(1,3)
	fmt.Println(a, b)

Below is the program output:

2 4
< Multiple return values Multiple return values >