Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement