Search⌘ K
AI Features

Solution Review: Multiple Return Values

Explore how to define and use Go functions that return multiple values. Understand the syntax for returning sum, product, and difference from two integers and how to capture these results in variables for practical use.

We'll cover the following...
Go (1.6.2)
package main
import (
"fmt"
)
func SumProductDiff(i, j int)(s int, p int, d int) {
s, p, d = i + j, i * j, i - j
return
}
func main() {
sum, prod, diff := SumProductDiff(3, 4)
fmt.Println("Sum:", sum, "| Product:", prod, "| Diff:", diff)
}

In the ...