August 2019
Beginner to intermediate
798 pages
17h 2m
English
The Go code of the slices.go program will hopefully clarify many things about slices and will be presented in five parts.
The first part of the program contains the expected preamble as well as the definition of two slices:
package main
import (
"fmt"
)
func main() {
aSlice := []int{1, 2, 3, 4, 5}
fmt.Println(aSlice)
integers := make([]int, 2)
fmt.Println(integers)
integers = nil
fmt.Println(integers)
The second part shows how to use the [:] notation to create a new slice that references an existing array. Remember that you are not creating a copy of the array, just a reference to it that will be verified in the output of the program:
anArray := [5]int{-1, -2, -3, -4, -5} refAnArray := anArray[:] fmt.Println(anArray) ...Read now
Unlock full access