Solution Review: Variable Number of Arguments

This lesson discusses the solution to the challenge given in the previous lesson.

Press + to interact
package main
import "fmt"
func main() {
// function calls for multiple arg.
fmt.Println(sumInts())
fmt.Println(sumInts(2, 3))
fmt.Println(sumInts(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
}
func sumInts(list ...int) (sum int){ // function to calculate sum of variable arg.
for _, v := range list {
sum = sum+v
}
return
}

Get hands-on with 1400+ tech skills courses.