I am trying to understand, What is difference between 1st and 2nd passing argument in function. In both case methods are functional and compiles.
1)
generateReport(capacities...)
func generateReport(capacities ...float64) {
for i, cap := range capacities {
fmt.Printf("Plant %d capacity %.0f\n", i, cap)
}
}
2)
generateReport(plantCapacities)
func generateReport(capacities []float64) {
for i, cap := range capacities {
fmt.Printf("Plant %d capacity %.0f\n", i, cap)
}
}
Have found few good samples
1) GolangBot - Variadic Function
2) Golang.org - Passing arguments as @Himanshu mentioned.