为什么切片a保持不变?是否append()生成新切片?
package main
import (
"fmt"
)
var a = make([]int, 7, 8)
func Test(slice []int) {
slice = append(slice, 100)
fmt.Println(slice)
}
func main() {
for i := 0; i < 7; i++ {
a[i] = i
}
Test(a)
fmt.Println(a)
}
输出:
[0 1 2 3 4 5 6 100]
[0 1 2 3 4 5 6]
Helenr
料青山看我应如是
慕桂英3389331
相关分类