Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.46 KB | None | 0 0
  1. import "fmt"
  2.  
  3. func main() {
  4.     a := []int{2, 3, 5, 7, 11, 13}
  5.     printSlice(a)
  6.  
  7.     // Slice the slice to give it zero length.
  8.     s := a[:0]
  9.     printSlice(s)
  10.  
  11.     // Extend its length.
  12.     s = a[1:4]
  13.     printSlice(s)
  14.     // Extend its length.
  15.     s = s[0:5]
  16.     printSlice(s)
  17.  
  18.  
  19.     // Drop its first two values.
  20.     s = a[2:]
  21.     printSlice(s)
  22.  
  23.     s = append(s, 35)
  24.     printSlice(s)
  25.     printSlice(a)
  26. }
  27.  
  28.  
  29. func printSlice(s []int) {
  30.     fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement