Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
14. Variadic Functions
//https://gobyexample.com/ // [_Variadic functions_](http://en.wikipedia.org/wiki/Variadic_function) // can be called with any number of trailing arguments. // For example, `fmt.Println` is a common variadic // function. package main import "fmt" // Here's a function that will take an arbitrary number // of `ints` as arguments. func sum(nums ...int) { fmt.Print(nums, " ") total := 0 for _, num := range nums { total += num } fmt.Println(total) } func main() { // Variadic functions can be called in the usual way // with individual arguments. sum(1, 2) sum(1, 2, 3) // If you already have multiple args in a slice, // apply them to a variadic function using // `func(slice...)` like this. nums := []int{1, 2, 3, 4} sum(nums...) }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
3. Variables
30.01.2020
15. Closures
AVL-GO-FLAT
13. Multiple Return Values
16. Recursion
multidimention_array
9. Slices
FizzBuzzPractice
31.01.2020
Please log in to post a comment.