下面的程序有意想不到的输出.
func main(){ s:=[]int{5} s=append(s,7) s=append(s,9) x:=append(s,11) y:=append(s,12) fmt.Println(s,x,y) }
输出: [5 7 9] [5 7 9 12] [5 7 9 12]
[5 7 9] [5 7 9 12] [5 7 9 12]
为什么是最后一个元素x 12?
x
12
arrays go slice
arrays ×1
go ×1
slice ×1