Home > front end >  Passing multiple string arguments to a variadic function
Passing multiple string arguments to a variadic function

Time:10-06

How the parameter s accepts an infinite number of arguments in a program where multiple strings arguments are passed.

Output

[]
[red blue]
[red blue green]
[red blue green yellow]

CodePudding user response:

I hope this helps:

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

func variadicExample(s ...string) {
    fmt.Println(s)
}
  •  Tags:  
  • go
  • Related