Source file tour/moretypes/making-slices.go

     1  //go:build OMIT
     2  
     3  package main
     4  
     5  import "fmt"
     6  
     7  func main() {
     8  	a := make([]int, 5)
     9  	printSlice("a", a)
    10  
    11  	b := make([]int, 0, 5)
    12  	printSlice("b", b)
    13  
    14  	c := b[:2]
    15  	printSlice("c", c)
    16  
    17  	d := c[2:5]
    18  	printSlice("d", d)
    19  }
    20  
    21  func printSlice(s string, x []int) {
    22  	fmt.Printf("%s len=%d cap=%d %v\n",
    23  		s, len(x), cap(x), x)
    24  }
    25  

View as plain text