Created
October 20, 2022 00:09
-
-
Save pgaijin66/9db757cfae362db13f7f4507fe22a9bd to your computer and use it in GitHub Desktop.
go_slice_without_copy
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 := 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