Last active
February 14, 2018 03:33
-
-
Save tomtsang/2c337435edf0913515614245486274d4 to your computer and use it in GitHub Desktop.
slice append change the array data
This file contains hidden or 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() { | |
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