Created
August 10, 2019 03:47
-
-
Save ealipio/99d30b0b180eeb1ee5f3faec13b91a3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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