Multiple arguments to a function
Package main import "FMT" /* Function call: 1 Function name: The name of the declared function must be the same as that of the called function. 2. The arguments must strictly match the parameters: Order, number, type, GetAdd (10,20) getAdd2(10,20) fun1(1.3,2.4,"hello")} func getAdd(a int,b int) {sum:=a+b fmt.Printf("%d+%d=%d\n",a,b,sum) } func getAdd2(a,b int) { fmt.Printf("a:%d,b:%d\n",a,b) } func fun1(a,b float64,c string) { fmt.Printf("a:%.2f,b:%.2f,c:%s\n",a,b,c) }Copy the code
Variable parameter
Package main import "FMT" func main() {/* Variable arguments: concept: a function whose arguments are of a certain type, but whose number is not specified, can use the variable arguments syntax: parameter names... For functions, mutable arguments are equivalent to a slice. When calling a function, you can pass in 0 to a pair of arguments Println and so on as mutable arguments, including append. A: If A function has other arguments, the variable argument should be placed at the end of the argument list. B: A parameter list has at most one variable argument. * / / / 1. The sum getSum1 () getSum1 (1, 2, 3, 4, 5) getSum1,2,3,4,5,6,7,8,9 (1) / / 2. Section s1: int [] = {1, 2, 3, 4, 5} getSum1 (s1)... Get ("hello",2.3,2,3,4)} func getSum1(nums... int) { //fmt.Printf("%T\n",nums)//[]int sum:=0 for i:=0; i<len(nums); I ++ {sum+=nums[I]} FMT.Println(" sum is: ",sum)} func get(STR String,f float64,a... int) { fmt.Println(str,f,a) fmt.printf("%T\n",a) }Copy the code