为什么同时append3个值后,cap会变成6呢? len = 5,cap = 6,slice = [0 1 2 3 4]
package main import "fmt" func main(){ var n []int printslice(n) n = append(n,0) printslice(n) n = append(n,1) printslice(n) n = append(n,2,3,4) printslice(n) n1 := make([]int,len(n),(cap(n))*2) copy(n1,n) printslice(n1) } func printslice(x []int){ fmt.Printf("len = %d,cap = %d,slice = %d\n",len(x),cap(x),x) len = 0,cap = 0,slice = [] len = 1,cap = 1,slice = [0] len = 2,cap = 2,slice = [0 1] len = 5,cap = 6,slice = [0 1 2 3 4] len = 5,cap = 12,slice = [0 1 2 3 4]