SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func main() {
  8.     fruits := make([]string, 5, 8)
  9.     fruits[0] = "plum"
  10.     fruits[1] = "apple"
  11.     fruits[2] = "pear"
  12.     fruits[3] = "grapes"
  13.     fruits[4] = "Banana"
  14.     //fruits[5] = "Banana"
  15.     //panic: runtime error: index out of range
  16.     // fmt.Printf("cap:%v \nlen:%v\nfruits:%v", cap(fruits), len(fruits), fruits)
  17.     inspectSlice(fruits)
  18. }
  19.  
  20. func inspectSlice(slice []string) {
  21.     fmt.Printf("Length[%d] Capacity[%d]\n", len(slice), cap(slice))
  22.     for i, s := range slice {
  23.         fmt.Printf("[%d] %p %s\n", i, &slice[i], s)
  24.     }
  25. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top