Variadic Functions

Let’s learn about variadic functions.

Variadic functions are functions that can accept a variable number of parameters—we already know about fmt.Println() and append(), which are both variadic functions that are widely used. In fact, most functions found in the fmt package are variadic.

General ideas and rules

The general ideas and rules behind variadic functions are as follows:

  • Variadic functions use the pack operator, which consists of a ..., followed by a data type. So, for a variadic function to accept a variable number of int values, the pack operator should be ...int.

  • The pack operator can only be used once in any given function. ...