August 2019
Beginner to intermediate
798 pages
17h 2m
English
You can create a slice from the elements of an existing array and you can copy an existing slice to another one using the copy() function. However, as the use of copy() can be very tricky, this subsection will try to clarify its usage with the help of the Go code of copySlice.go, which will be presented in four parts.
The first part of the program comes with the next Go code:
package main import ( "fmt" ) func main() { a6 := []int{-10, 1, 2, 3, 4, 5} a4 := []int{-1, -2, -3, -4} fmt.Println("a6:", a6) fmt.Println("a4:", a4) copy(a6, a4) fmt.Println("a6:", a6) ...Read now
Unlock full access