From f0c2e76a4f783244d9fb58b08579882143f2f8ca Mon Sep 17 00:00:00 2001 From: sebastian Date: Thu, 9 Nov 2023 14:14:28 +0100 Subject: [PATCH] Section10-82 --- Section10/81.go | 22 ++++++++++++++++++++++ Section10/82.go | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Section10/81.go create mode 100644 Section10/82.go diff --git a/Section10/81.go b/Section10/81.go new file mode 100644 index 0000000..1e8a601 --- /dev/null +++ b/Section10/81.go @@ -0,0 +1,22 @@ +package main + +import "fmt" + +func main() { + numbers := []int{2, 3} + + numbers = append(numbers, 10) + fmt.Println(numbers) + + numbers = append(numbers, 20, 30, 40) + fmt.Println(numbers) + + n := []int{100, 200} + numbers = append(numbers, n...) + fmt.Println(numbers) + + src := []int{10, 20, 30} + dst := make([]int, len(src)) + nn := copy(dst, src) + fmt.Println(src, dst, nn) +} diff --git a/Section10/82.go b/Section10/82.go new file mode 100644 index 0000000..3e79671 --- /dev/null +++ b/Section10/82.go @@ -0,0 +1,22 @@ +package main + +import "fmt" + +func main() { + a := [5]int{1, 2, 3, 4, 5} + b := a[1:3] + fmt.Printf("%v, %T\n", b, b) + + s1 := []int{1, 2, 3, 4, 5, 6} + s2 := s1[1:3] + fmt.Println(s2) + fmt.Println(s1[2:]) + fmt.Println(s1[:3]) + fmt.Println(s1[:]) + + s1 = append(s1[:4], 100) + fmt.Println(s1) + + s1 = append(s1[:4], 200) + fmt.Println(s1) +}