Recall & Review
beginner
What is the purpose of the
main package in Go?The
main package is special in Go because it defines an executable program. It tells the Go compiler to build a runnable application instead of a library.Click to reveal answer
beginner
What is the role of the
main function in a Go program?The
main function is the entry point of a Go program. When you run the program, Go starts executing from this function.Click to reveal answer
beginner
Can a Go program have multiple
main functions?No, a Go program can have only one
main function inside the main package. This function is where the program starts running.Click to reveal answer
intermediate
What happens if you try to run a Go program without a
main function in the main package?The program will not compile. Go requires a
main function in the main package to know where to start execution.Click to reveal answer
beginner
How do you define the
main package and main function in Go? Show a simple example.You write
package main at the top, then define func main() { }. For example:<br>package main
func main() {
println("Hello, world!")
}Click to reveal answer
What is the special package name that makes a Go program executable?
✗ Incorrect
The
main package is the special package that tells Go to build an executable program.Where does a Go program start running?
✗ Incorrect
The
main function is the entry point where execution begins.Can you have multiple
main functions in one Go program?✗ Incorrect
A Go program must have exactly one
main function in the main package.What happens if the
main function is missing in the main package?✗ Incorrect
Go requires a
main function to compile an executable program.Which of these is the correct way to start a Go program?
✗ Incorrect
The program must be in the
main package and have a main function.Explain why the
main package and main function are important in Go programs.Think about how Go knows where to start running your code.
You got /4 concepts.
Write a simple Go program that prints "Hello, Go!" using the main package and main function.
Start with package main, then define func main, then print the message.
You got /3 concepts.