-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice3.go
52 lines (35 loc) · 841 Bytes
/
slice3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import "fmt"
func main() {
dest := make([]string, 3)
fmt.Println(dest)
var src = []string{"ram", "krishna", "govinda"}
//copy
copy(dest, src)
fmt.Println(dest)
src[0] = "abi"
fmt.Println(dest)
fmt.Println(src)
//when you reference the scenario is different
newsrc := src[0:3]
fmt.Println(newsrc)
src[0] = "vardhini"
fmt.Println("Src: ", src)
fmt.Println("Dest: ", dest)
fmt.Println("New Source: ", newsrc)
//some more functionality with the slice
fmt.Println(src)
fmt.Println("src :3", src[:3])
fmt.Println("src 0:2", src[0:2])
fmt.Println("src 2:", src[2:])
gameMap := [][]string{
make([]string, 3),
make([]string, 5),
([]string{"-", "-"}),
}
fmt.Println(gameMap)
//make change in the size
gameMap[0] = make([]string, 6)
gameMap[1] = make([]string, 10)
fmt.Println(gameMap)
}