0
0
Goprogramming~20 mins

Output using fmt.Println in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go fmt.Println Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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)
}
AHelloWorld2024
BHello World 2024
C"Hello World 2024"
DHello, World, 2024
Attempts:
2 left
๐Ÿ’ก Hint
fmt.Println separates arguments with spaces by default.
โ“ Predict Output
intermediate
2: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")
}
A
Line1
Line2
BLine1\nLine2
CLine1 Line2
DLine1\n Line2
Attempts:
2 left
๐Ÿ’ก Hint
The string contains an escape sequence for newline.
โ“ Predict Output
advanced
2: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)
}
A1,2,3
B1 2 3
C[1 2 3]
D[]int{1, 2, 3}
Attempts:
2 left
๐Ÿ’ก Hint
fmt.Println prints slices with brackets and spaces.
โ“ Predict Output
advanced
2: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)
}
A&10
B10
Cp
D0xc0000140b0
Attempts:
2 left
๐Ÿ’ก Hint
Printing a pointer shows its memory address.
โ“ Predict Output
expert
2: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)
    }
}
A
42
84
B
42
42
C
interface value
84
D
42
<nil>
Attempts:
2 left
๐Ÿ’ก Hint
Type assertion extracts the int value from interface{}.