Go course

Constants and FormattingQuiz: Constants and Formatting

Go

Display

Theme

Constants and Formatting · Quiz

Quiz: Constants and Formatting

Time to test what you know about const, fmt.Printf, fmt.Sprintf, and format verbs. Answer every question in the right-hand panel.

  1. Question 1 of 6What happens when the following code is compiled?
    const kapasitas = 40
    
    func main() {
    	kapasitas = 45
    }
  2. Question 2 of 6Which declaration is NOT valid?
  3. Question 3 of 6What does the following code print?
    fmt.Printf("%.1f|%q\n", 4.26, "ok")
  4. Question 4 of 6What does the following line print?
    x := 7
    fmt.Printf("%T\n", x)
  5. Question 5 of 6What does the variable s contain?
    s := fmt.Sprintf("[%-5s][%04d]", "ab", 7)
  6. Question 6 of 6What's the main difference between fmt.Printf and fmt.Sprintf?