Skip to content

Instantly share code, notes, and snippets.

@pgaijin66
Created October 20, 2022 00:09
Show Gist options
  • Save pgaijin66/9db757cfae362db13f7f4507fe22a9bd to your computer and use it in GitHub Desktop.
Save pgaijin66/9db757cfae362db13f7f4507fe22a9bd to your computer and use it in GitHub Desktop.
go_slice_without_copy
package main
import (
"fmt"
)
func main(){
slice := []int{0,1,2,3}
fmt.Println(slice)
newslice1 := slice[:1]
fmt.Println(newslice1)
newslice2 := slice[2:]
fmt.Println(newslice2)
newslice1 = append(newslice1, newslice2...)
fmt.Println(newslice1)
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