Go course

PointersQuiz: Pointers

Go

Display

Theme

Pointers · Quiz

Quiz: Pointers

Test your understanding of &, *, pass by value, pointer receivers, and nil pointers. Answer every question in the right-hand panel.

  1. Question 1 of 6What does the following program print?
    x := 5
    p := &x
    *p = 9
    fmt.Println(x)
  2. Question 2 of 6What does the following program print?
    type Akun struct{ Saldo int }
    
    func tambah(a Akun) { a.Saldo += 100 }
    
    func main() {
    	akun := Akun{Saldo: 50}
    	tambah(akun)
    	fmt.Println(akun.Saldo)
    }
  3. Question 3 of 6Which method actually changes the caller's Level field?
  4. Question 4 of 6What happens when this code runs?
    var a *Anggota
    fmt.Println(a.Nama)
  5. Question 5 of 6Serang() is defined as func (k *Ksatria) Serang(). Which satisfies the interface Penyerang { Serang() }?
  6. Question 6 of 6Which situation LEAST needs a pointer?