Golang ProgramsGolang Programs

Passing multiple string arguments to a variadic function

The parameter s accepts an infinite number of arguments. The tree-dotted ellipsis tells the compiler that this string will accept, from zero to multiple values.
package main

import "fmt"

func main() {
	
	variadicExample()
	variadicExample("red", "blue")
	variadicExample("red", "blue", "green")
	variadicExample("red", "blue", "green", "yellow")
}

func variadicExample(s ...string) {
	fmt.Println(s)
}
C:\golang\example>go run test1.go
[]
[red blue]
[red blue green]
[red blue green yellow]

C:\golang\example>
In the above example, we have called the function with single and multiple arguments; and without passing any arguments.