Section11 Complete

This commit is contained in:
2023-11-23 13:01:04 +01:00
parent a2dc92f941
commit 1c925bc32a
3 changed files with 70 additions and 0 deletions

24
Section11/89-7.go Normal file
View File

@@ -0,0 +1,24 @@
/*
Consider the following slice declaration:
friends := []string{"Marry", "John", "Paul", "Diana"}
Using append() 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 := []string{}
yourFriends = append(yourFriends, friends...)
yourFriends[0] = "Dan"
fmt.Println(friends, yourFriends)
}