Go course

SlicesQuiz: Slices

Go

Display

Theme

Slices · Quiz

Quiz: Slices

Test your understanding of arrays, slices, make, len/cap, append, slicing, variadic functions, and the slices package.

  1. Question 1 of 6What is the main difference between an array and a slice in Go?
  2. Question 2 of 6What are the len and cap of s?
    s := make([]int, 2, 10)
    s = append(s, 7)
  3. Question 3 of 6What does the following code print?
    menu := []string{"bakso", "soto", "rawon", "gudeg"}
    fmt.Println(menu[1:3])
  4. Question 4 of 6What does the following code print?
    a := []int{1, 2, 3}
    b := a[:2]
    b[0] = 99
    fmt.Println(a)
  5. Question 5 of 6You want to call func rata(nilai ...float64) float64 with data := []float64{7.5, 8, 9}. The correct way to write it is...
  6. Question 6 of 6What does skor hold after the following code runs?
    skor := []int{3, 1, 2}
    urut := slices.Clone(skor)
    slices.Sort(urut)