August 2019
Beginner to intermediate
798 pages
17h 2m
English
You can create a new slice literal as follows:
aSliceLiteral := []int{1, 2, 3, 4, 5}
This means that slice literals are defined just like arrays but without the element count. If you put an element count in a definition, you will get an array instead.
However, there is also the make() function, which allows you to create empty slices with the desired length and capacity based on the parameters passed to make(). The capacity parameter can be omitted. In that case, the capacity of the slice will be the same as its length. So, you can define a new empty slice with 20 places that can be automatically expanded when needed as follows:
integer := make([]int, 20)
Please note that Go automatically initializes ...
Read now
Unlock full access