Created
October 20, 2022 00:08
-
-
Save pgaijin66/e537ea5552e0ba7adcc867a36c339200 to your computer and use it in GitHub Desktop.
copy_slice_go
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(){ | |
slice := []int{0,1,2,3} | |
fmt.Println(slice) | |
newslice1 := make([]int, len(slice)) | |
copy(newslice1, slice) | |
newslice1 = newslice1[:1] | |
fmt.Println(newslice1) | |
newslice2:= make([]int, len(slice)) | |
copy(newslice2, slice) | |
newslice2 = newslice2[2:] | |
fmt.Println(newslice2) | |
newslice1 = append(newslice1, newslice2...) | |
newslice1 = append(newslice1, newslice2...) | |
fmt.Println(newslice1) | |
fmt.Println(slice) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment