awesome-patterns/the_go_programming_language/ch04/slice.go

15 lines
339 B
Go
Raw Normal View History

2018-04-26 13:36:58 +03:00
package main
import "fmt"
func main() {
months := [...]string{1: "Jan", 2: "Feb", 3: "Mar", 4: "Apr"}
// create a new slice by syntax [m:n]
m1 := months[1:3]
m2 := months[2:4]
// Two slices point to the same underlaying array, when one changes the other changes also
fmt.Println(m1, m2)
m2[0] = "Feb updated"
fmt.Print(m1, m2)
}