Newer
Older
01_hello / collection / append.go
yhornisse on 24 Sep 2021 660 bytes rename dir
package main

import "fmt"

func main() {
	ary := []int{}
	for i := 0; i < 10; i++ {
		ary = append(ary, i)
		fmt.Printf("%d: %p len:%d cap:%d %v\n", i, ary, len(ary), cap(ary), ary)
	}
	/*
	   0: 0x140000180b8 len:1 cap:1 [0]
	   1: 0x140000180e0 len:2 cap:2 [0 1]
	   2: 0x1400001e040 len:3 cap:4 [0 1 2]
	   3: 0x1400001e040 len:4 cap:4 [0 1 2 3]
	   4: 0x14000014100 len:5 cap:8 [0 1 2 3 4]
	   5: 0x14000014100 len:6 cap:8 [0 1 2 3 4 5]
	   6: 0x14000014100 len:7 cap:8 [0 1 2 3 4 5 6]
	   7: 0x14000014100 len:8 cap:8 [0 1 2 3 4 5 6 7]
	   8: 0x1400006e000 len:9 cap:16 [0 1 2 3 4 5 6 7 8]
	   9: 0x1400006e000 len:10 cap:16 [0 1 2 3 4 5 6 7 8 9]
	*/
}