Go · Stage 6 – Reusable Code · Lesson 38 of 64

Multiple Return Values

Return more than one result from a Go function.

Go code

func size() (int, int) {
    return 640, 480
}

width, height := size()
fmt.Println(width, height)
Line-by-line explanation
  1. The signature promises two ints.
  2. Return sends both values in order.
  3. Two variables receive them.
  4. Println displays both.
Expected output
640 480

This is the expected result.