Junior — Middle
Kas on võimalik määrata algpikkus lõike loomisel?
sobes.tech AI
Vastus AI-lt
In Go, when creating a slice, you can set the initial length using the make function. The syntax is: make([]T, length, capacity), where length is the initial length of the slice, and capacity is its capacity (optional parameter). For example:
s := make([]int, 5) // slice with length 5 and capacity 5
In this case, the slice s will have a length of 5, and all elements will be initialized with the default values for the int type (i.e., 0). You can also specify a capacity larger than the length:
s := make([]int, 5, 10) // length 5, capacity 10
Therefore, yes, it is possible to set an initial length for the slice.