Sobes.tech
Junior — Senior

How append changes the original slice

livecode

Task condition

It is necessary to determine which values will be output to the console after the slice obtained from another slice has the append function applied.

func example() {
    src := []int{1, 2, 3}

    sub := src[:2]
    sub = append(sub, 4)

    fmt.Println(sub) // 1,2,4
    fmt.Println(src) // 1,2,4
}