Skip to content

Instantly share code, notes, and snippets.

@mayra-cabrera
Created October 27, 2015 23:57
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 mayra-cabrera/43e9544f0de45363b0fb to your computer and use it in GitHub Desktop.
Save mayra-cabrera/43e9544f0de45363b0fb to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
orgSlice := make([]string, 5, 8)
orgSlice[0] = "Apple"
orgSlice[1] = "Orange"
orgSlice[2] = "Banana"
orgSlice[3] = "Grape"
orgSlice[4] = "Plum"
orgSlice2 := orgSlice[2:4]
fmt.Println(orgSlice2)
fmt.Printf("%s: %d\n", "Cap", cap(orgSlice2))
fmt.Printf("%s: %d\n", "Len", cap(orgSlice2))
for _, v := range orgSlice2 {
fmt.Println("-" + v)
}
orgSlice3 := orgSlice2[1:cap(orgSlice2)]
fmt.Println(orgSlice3)
fmt.Printf("%s: %d\n", "Cap", cap(orgSlice3))
fmt.Printf("%s: %d\n", "Len", cap(orgSlice3))
for _, v := range orgSlice3 {
fmt.Println("-" + v)
}
orgSlice[3] = "hola"
fmt.Println("orgSlice: " + orgSlice[3])
fmt.Println("orgSlice: " + orgSlice2[1])
fmt.Println("orgSlice: " + orgSlice3[0])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment