Challenge - 5 Problems
Go Main Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of a simple main function
What is the output of this Go program?
Go
package main import "fmt" func main() { fmt.Println("Hello, Go!") }
Attempts:
2 left
๐ก Hint
Look at what fmt.Println prints exactly.
โ Incorrect
The main function runs and prints the string exactly as given with a newline.
โ Predict Output
intermediate2:00remaining
What happens if main package is missing?
What error will this Go program produce?
Go
package mainAttempts:
2 left
๐ก Hint
The Go compiler requires a main package with main function to run an executable.
โ Incorrect
Only package named 'main' with a main function can be compiled as an executable.
๐ง Debug
advanced2:00remaining
Why does this program not run?
This Go program compiles but does not run as expected. Why?
Go
package main func Main() { // empty }
Attempts:
2 left
๐ก Hint
Go is case sensitive for function names.
โ Incorrect
The entry point must be 'main' exactly, not 'Main'.
๐ง Conceptual
advanced2:00remaining
Role of main package in Go
Which statement best describes the role of the main package in Go?
Attempts:
2 left
๐ก Hint
Think about what happens when you run 'go run' or 'go build'.
โ Incorrect
The main package contains the main function which is the program's entry point.
โ Predict Output
expert3:00remaining
Output of multiple main functions in different files
Given two files in the same main package, what is the output when running the program?
File1.go:
package main
import "fmt"
func main() {
fmt.Println("Start")
helper()
}
File2.go:
package main
import "fmt"
func helper() {
fmt.Println("Helper called")
}
Attempts:
2 left
๐ก Hint
Functions in the same package can call each other.
โ Incorrect
The main function runs first printing 'Start', then calls helper which prints 'Helper called'.