Sobes.tech
Junior — Senior

Determining the length and capacity of a slice before and after calling a function

livecode

Task condition

It is necessary to find out how the length and capacity parameters of the slice will change before and after executing the add function.

numbers := make([]int, 0, 1)
numbers = append(numbers, 1)
// len = 1, cap = 1

add(numbers, 2)
// len = 1, cap = 1

func add(slice []int, value int) {
    slice = append(slice, value)
}