package main import "fmt" func main() { var s []int printSlice(s) // append works on nil slices. s = append(s, 0) printSlice(s) // The slice grows as needed. s = append(s, 1) printSlice(s) // We can add more than one element at a time. s = append(s, 2, 3, 4) printSlice(s) } func printSlice(s []int) { fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s) }
の
s = append(s, 2, 3, 4) printSlice(s)がlen=5 cap=8 [0 1 2 3 4]とcapが8になるのはどうしてなのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/01/04 02:53
2020/01/04 06:57 編集
退会済みユーザー
2020/01/04 17:02