Go语言 之切片作为函数参数
package main import ( "fmt" ) func InitData(s []int) { for i := 0; i < len(s); i++ { s[i] = i } } //切片作为函数参数是引用传递 func main() { s := make([]int, 10) InitData(s) fmt.Println(s) //[0 1 2 3 4 5 6 7 8 9] }
package main import ( "fmt" ) func InitData(s []int) { for i := 0; i < len(s); i++ { s[i] = i } } //切片作为函数参数是引用传递 func main() { s := make([]int, 10) InitData(s) fmt.Println(s) //[0 1 2 3 4 5 6 7 8 9] }