Slices
package main import "fmt" func main() { // An array and some slices thereof. arr := [14]int{9,4,-5,7,11,87,3,12,8,3,19,-3,18,6} sl1 := arr[3:9] sl2 := arr[5:10] // Print the contents of each slice, which is a // portion of the underlying array. for i := 0 ; i < len(sl1) ; i++ { fmt.Printf("%2d ", sl1[i]) } fmt.Println() fmt.Print(" ") for i := 0 ; i < len(sl2) ; i++ { fmt.Printf("%2d ", sl2[i]) } fmt.Println("\n") // Now, let's change some positions. We change positions // using each slice and also the underlying array, but // everyone refes to the same array. sl1[2] = -2 sl2[2] = 72 arr[6] = 10 // Once again. for i := 0 ; i < len(sl1) ; i++ { fmt.Printf("%2d ", sl1[i]) } fmt.Println() fmt.Print(" ") for i := 0 ; i < len(sl2) ; i++ { fmt.Printf("%2d ", sl2[i]) } fmt.Println() }