Skip to content

Instantly share code, notes, and snippets.

@ealipio
Created August 10, 2019 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ealipio/99d30b0b180eeb1ee5f3faec13b91a3c to your computer and use it in GitHub Desktop.
Save ealipio/99d30b0b180eeb1ee5f3faec13b91a3c to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
fruits := make([]string, 5, 8)
fruits[0] = "plum"
fruits[1] = "apple"
fruits[2] = "pear"
fruits[3] = "grapes"
fruits[4] = "Banana"
//fruits[5] = "Banana"
//panic: runtime error: index out of range
// fmt.Printf("cap:%v \nlen:%v\nfruits:%v", cap(fruits), len(fruits), fruits)
inspectSlice(fruits)
}
func inspectSlice(slice []string) {
fmt.Printf("Length[%d] Capacity[%d]\n", len(slice), cap(slice))
for i, s := range slice {
fmt.Printf("[%d] %p %s\n", i, &slice[i], s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment