- Learn Data Structures and Algorithms with Golang
- Bhagvan Kommadi
- 133字
- 2021-06-24 15:37:40
Variadic functions
A function in which we pass an infinite number of arguments, instead of passing them one at a time, is called a variadic function. The type of the final parameter is preceded by an ellipsis (...), while declaring a variadic function; this shows us that the function might be called with any number of arguments of this type.
Variadic functions can be invoked with a variable number of parameters. fmt.Println is a common variadic function, as follows:
//main method
func main() {
var customers []Customer
customers = GetCustomers()
fmt.Println("Before Insert",customers)
var customer Customer
customer.CustomerName = "Arnie Smith"
customer.SSN = "2386343"
InsertCustomer(customer)
customers = GetCustomers()
fmt.Println("After Insert",customers)
}
Run the following commands:
go run database_operations.go
The following screenshot displays the output:
![](https://epubservercos.yuewen.com/AA6936/19470380301498306/epubprivate/OEBPS/Images/9f6c143f-b52f-4e9d-8914-eef2a81aa9d8.png?sign=1739025885-4lxHQpMcUfDIfPPQJ0PTMmpokM0QMimh-0-66e60470288e121140a900af119e27c1)
Let's start the update operation in the next section.