Skip to content

Instantly share code, notes, and snippets.

@pgaijin66
Created October 20, 2022 00:08
Show Gist options
  • Save pgaijin66/e537ea5552e0ba7adcc867a36c339200 to your computer and use it in GitHub Desktop.
Save pgaijin66/e537ea5552e0ba7adcc867a36c339200 to your computer and use it in GitHub Desktop.
copy_slice_go
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