Files
2023-11-23 13:01:04 +01:00

24 lines
501 B
Go

/*
Consider the following slice declaration:
friends := []string{"Marry", "John", "Paul", "Diana"}
Using copy() function create a copy of the slice. Prove that the slices
are not connected by modifying one slice and notice that the other slice is not modified.
*/
package main
import "fmt"
func main() {
friends := []string{"Marry", "John", "Paul", "Diana"}
yourFriends := make([]string, len(friends))
copy(yourFriends, friends)
yourFriends[0] = "Dan"
fmt.Println(friends, yourFriends)
}