Challenge - 5 Problems
Go fmt.Println Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of fmt.Println with multiple arguments
What is the output of this Go code snippet?
Go
package main import "fmt" func main() { fmt.Println("Hello", "World", 2024) }
Attempts:
2 left
๐ก Hint
fmt.Println separates arguments with spaces by default.
โ Incorrect
fmt.Println prints each argument separated by a space and adds a newline at the end.
โ Predict Output
intermediate2:00remaining
Output of fmt.Println with newline characters
What will this Go program print?
Go
package main import "fmt" func main() { fmt.Println("Line1\nLine2") }
Attempts:
2 left
๐ก Hint
The string contains an escape sequence for newline.
โ Incorrect
The \n inside the string creates a new line when printed by fmt.Println.
โ Predict Output
advanced2:00remaining
Output of fmt.Println with slice argument
What is the output of this Go code?
Go
package main import "fmt" func main() { nums := []int{1, 2, 3} fmt.Println(nums) }
Attempts:
2 left
๐ก Hint
fmt.Println prints slices with brackets and spaces.
โ Incorrect
fmt.Println prints slices in a format with square brackets and spaces between elements.
โ Predict Output
advanced2:00remaining
Output of fmt.Println with pointer variable
What will this Go program print?
Go
package main import "fmt" func main() { x := 10 p := &x fmt.Println(p) }
Attempts:
2 left
๐ก Hint
Printing a pointer shows its memory address.
โ Incorrect
fmt.Println prints the memory address stored in the pointer variable.
โ Predict Output
expert2:00remaining
Output of fmt.Println with interface and type assertion
What is the output of this Go code?
Go
package main import "fmt" func main() { var i interface{} = 42 fmt.Println(i) if v, ok := i.(int); ok { fmt.Println(v * 2) } }
Attempts:
2 left
๐ก Hint
Type assertion extracts the int value from interface{}.
โ Incorrect
The interface holds 42, printing it shows 42, then doubling prints 84.