Go course

FunctionsQuiz: Functions

Go

Display

Theme

Functions · Quiz

Quiz: Functions

Test what you know about parameters, multiple return values, guard clauses, functions as values, and defer. Answer every question in the right-hand panel.

  1. Question 1 of 6What does the following program print?
    func gandakan(x int) {
    	x = x * 2
    }
    
    func main() {
    	n := 10
    	gandakan(n)
    	fmt.Println(n)
    }
  2. Question 2 of 6How do you take ONLY the second value from a function that returns (int, string)?
    func data() (int, string) { return 7, "tujuh" }
  3. Question 3 of 6What does hitung() return?
    func hitung() (total int) {
    	total = 5
    	total += 3
    	return
    }
  4. Question 4 of 6What is the type of the variable f?
    func cek(nama string, umur int) bool {
    	return umur >= 17
    }
    
    f := cek
  5. Question 5 of 6What does the following program print?
    func main() {
    	defer fmt.Print("A")
    	defer fmt.Print("B")
    	fmt.Print("C")
    }
  6. Question 6 of 6What does the following code print?
    skor := 10
    defer fmt.Println(skor)
    skor = 50