Go course

MapsQuiz: Maps

Go

Display

Theme

Maps · Quiz

Quiz: Maps

Test your understanding of maps in Go: creating them, reading with comma-ok, iterating, and how they behave like references. Answer every question in the right-hand panel.

  1. Question 1 of 6What does the following program print?
    stok := map[string]int{"apel": 4}
    fmt.Println(stok["jeruk"])
  2. Question 2 of 6What happens when this code runs?
    var skor map[string]int
    skor["rina"] = 10
  3. Question 3 of 6How do you tell a missing key apart from a key whose value is 0?
  4. Question 4 of 6A program prints a map's contents with for range. What order does the output come in?
  5. Question 5 of 6What does the following program print?
    func reset(m map[string]int) {
    	m["hp"] = 100
    }
    
    func main() {
    	k := map[string]int{"hp": 20}
    	reset(k)
    	fmt.Println(k["hp"])
    }
  6. Question 6 of 6Why does the second line of this code fail to compile?
    tim := map[string]Pemain{"a": {Nama: "Dodi", Level: 1}}
    tim["a"].Level = 2