copy_append_slice.go 338 B

12345678910111213141516
  1. package main
  2. import "fmt"
  3. func main() {
  4. sl_from := []int{1,2,3}
  5. sl_to := make([]int,10)
  6. n := copy(sl_to, sl_from)
  7. fmt.Println(sl_to) // output: [1 2 3 0 0 0 0 0 0 0]
  8. fmt.Printf("Copied %d elements\n", n) // n == 3
  9. sl3 := []int{1,2,3}
  10. sl3 = append(sl3, 4, 5, 6)
  11. fmt.Println(sl3) // output: [1 2 3 4 5 6]
  12. }