Skip to content

Instantly share code, notes, and snippets.

@tomtsang
Last active February 14, 2018 03:33
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 tomtsang/2c337435edf0913515614245486274d4 to your computer and use it in GitHub Desktop.
Save tomtsang/2c337435edf0913515614245486274d4 to your computer and use it in GitHub Desktop.
slice append change the array data
package main
import (
"fmt"
)
func main() {
array1 := [...]string{"a", "b", "c", "d", "e", "f"}
slice1 := array1[:4]
fmt.Println(slice1)
slice1 = append(slice1, "e2", "f2")
fmt.Println(slice1)
fmt.Println(array1)
slice2 := array1[:4]
slice3 := append(slice2, "e3", "f3")
fmt.Println(slice1)
fmt.Println(slice2)
fmt.Println(slice3)
fmt.Println(array1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment