Sobes.tech
Junior — Senior
49

Какой будет вывод программы

Условие задачи

Определите, какой текст будет напечатан в каждой из точек вывода программы.

import (
  "fmt"
)

func main() {
  nums := make([]int, 1, 3)
  fmt.Println(nums) // <- what's the output?

  appendSlice(nums, 1)
  fmt.Println(nums) // <- what's the output?

  copySlice(nums, []int{2,3})
  fmt.Println(nums) // <- what's the output?

  mutateSlice(nums, 1, 4)
  fmt.Println(nums) // <- what's the output?
}

func appendSlice(sl []int, val int) {
  sl = append(sl, val)
}

func copySlice(sl, cp []int){
  copy(sl, cp)
}

func mutateSlice(sl []int, idx, val int) {
  sl[idx] = val
}