Skip to content

Instantly share code, notes, and snippets.

@tomtsang
Created February 8, 2018 01:54
Show Gist options
  • Select an option

  • Save tomtsang/f035c8f26dac689b537e169a50dfdf78 to your computer and use it in GitHub Desktop.

Select an option

Save tomtsang/f035c8f26dac689b537e169a50dfdf78 to your computer and use it in GitHub Desktop.
slice-copy-append.go
package main
import "fmt"
func main() {
sl_from := []int{1, 2, 3}
sl_to := make([]int, 10)
n := copy(sl_to, sl_from)
fmt.Println(sl_to)
fmt.Printf("Copied %d elements\n", n) // n == 3
sl3 := []int{1, 2, 3}
sl3 = append(sl3, 4, 5, 6)
fmt.Println(sl3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment