mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 19:41:43 +08:00
17 lines
336 B
Go
17 lines
336 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
slFrom := []int{1, 2, 3}
|
|
slTo := make([]int, 10)
|
|
|
|
n := copy(slTo, slFrom)
|
|
fmt.Println(slTo) // output: [1 2 3 0 0 0 0 0 0 0]
|
|
fmt.Printf("Copied %d elements\n", n) // n == 3
|
|
|
|
sl3 := []int{1, 2, 3}
|
|
sl3 = append(sl3, 4, 5, 6)
|
|
fmt.Println(sl3) // output: [1 2 3 4 5 6]
|
|
}
|