0
0
Goprogramming~20 mins

Go program structure - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of a simple Go program
What is the output of this Go program?
Go
package main
import "fmt"
func main() {
    fmt.Println("Hello, Go!")
}
ACompilation error
Bhello, go!
CHello Go!
DHello, Go!
Attempts:
2 left
๐Ÿ’ก Hint
Look at the exact string inside fmt.Println and remember Go is case-sensitive.
โ“ Predict Output
intermediate
2:00remaining
Variable declaration and output
What will this Go program print?
Go
package main
import "fmt"
func main() {
    var x int = 5
    fmt.Println(x)
}
ACompilation error
B5
C0
Dx
Attempts:
2 left
๐Ÿ’ก Hint
The variable x is assigned 5 before printing.
โ“ Predict Output
advanced
2:00remaining
Understanding package and import
What error does this Go program produce?
Go
package main
func main() {
    fmt.Println("Hi")
}
Aundefined: fmt
Bno error, prints Hi
Csyntax error: missing import
Druntime error
Attempts:
2 left
๐Ÿ’ก Hint
Check if the fmt package is imported before using it.
โ“ Predict Output
advanced
2:00remaining
Multiple functions and main execution
What is the output of this Go program?
Go
package main
import "fmt"
func greet() {
    fmt.Println("Hello")
}
func main() {
    greet()
    fmt.Println("World")
}
A
Hello
World
B
World
Hello
CHello World
DCompilation error
Attempts:
2 left
๐Ÿ’ก Hint
Functions run in the order they are called inside main.
๐Ÿง  Conceptual
expert
2:00remaining
Go program entry point and package rules
Which statement about Go program structure is correct?
AThe main() function can be in any package, not necessarily main.
BGo programs can run without a main() function if package main is present.
CEvery Go executable program must have package main and a main() function.
DPackages are optional in Go programs.
Attempts:
2 left
๐Ÿ’ก Hint
Think about what Go requires to start running a program.