March 2019
Intermediate to advanced
336 pages
9h 9m
English
Slices are passed by referring to functions. Big slices can be passed to functions without impacting performance. Passing a slice as a reference to a function is demonstrated in the code as follows (slices.go):
//twiceValue method given slice of int typefunc twiceValue(slice []int) { var i int var value intfor i, value = range slice { slice[i] = 2*value } }// main methodfunc main() { var slice = []int{1,3,5,6} twiceValue(slice) var i int for i=0; i< len(slice); i++ { fmt.Println(“new slice value”, slice[i])}}
Run the following command:
go run slices.go
The following screenshot displays the output:

Now that we know what slices ...
Read now
Unlock full access