Go-函数多个形参

 

函数多个形参

 1 package main
 2 
 3 import "fmt"
 4 
 5 func test(a int, agrs ...int) {
 6     fmt.Println("a=", a)
 7     fmt.Println("len(agrs)=", len(agrs))
 8     for i := 0; i < len(agrs); i++ {
 9         fmt.Printf("agrs[%d]=%d\t", i, agrs[i])
10     }
11 }
12 
13 func main() {
14     test(1, 2, 3, 4)
15 }
16 //输出
17 /*
18 a= 1
19 len(agrs)= 3
20 agrs[0]=2       agrs[1]=3       agrs[2]=4
21 */
View Code

 

转载于:https://www.cnblogs.com/Paul-watermelon/articles/10851735.html