SHARE
TWEET

Untitled

a guest Sep 15th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func myAppend(sl []int, val int) []int{
  2.     sl = append(sl, val)
  3.     printSlice(sl)
  4.     return sl
  5. }
  6.  
  7. func printSlice(sl []int) {
  8.     fmt.Printf("Slice %v\n", sl)
  9.     fmt.Printf("Len %v, Cap %v\n\n", len(sl), cap(sl))
  10. }
  11.  
  12. func main() {
  13.     sl := make([]int, 1)
  14.     printSlice(sl)
  15.     for i := 1; i < 5; i ++ {
  16.         sl = myAppend(sl, i)
  17.     }
  18. }
  19.  
  20. /**
  21. * Slice [0]
  22. * Len 1, Cap 1
  23. *
  24. * Slice [0 1]
  25. * Len 2, Cap 2
  26. *
  27. * Slice [0 1 2]
  28. * Len 3, Cap 4
  29. *
  30. * Slice [0 1 2 3]
  31. * Len 4, Cap 4
  32. *
  33. * Slice [0 1 2 3 4]
  34. * Len 5, Cap 8
  35. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top