Why doesn't copy() copy a slice in Go? Or am I doing something wrong?
Hello everyone! I recently started learning Go and encountered an unclear problem when working with slices. I needed to duplicate one slice into another so that I could later modify the copy independently of the original. I read that there is a built-in `copy()` function for this.
I wrote this code:
```go
package main
import "fmt"
func main() {
original := []int{1, 2, 3, 4, 5}
var copySlice []int
copy(copySlice, original)
fmt.Println("original:", original)
fmt.Println("copy:", copySlice)
}
```
But the output gave me an empty slice! `copySlice` remained `[]`. I expected that after `copy()`, `copySlice` would have the same elements as `original`.
Then I tried another approach — first declared a slice with length but without values:
```go
copySlice2 := make([]int,