Recall & Review
beginner
What is the basic structure of a Go program?
A Go program starts with a <code>package</code> declaration, followed by import statements, and then the <code>func main()</code> function where the program execution begins.Click to reveal answer
beginner
What is the purpose of the
package main declaration in a Go program?The
package main tells the Go compiler that this program is an executable and should have a main() function as the entry point.Click to reveal answer
beginner
Where does the execution of a Go program start?
Execution starts at the
main() function inside the package main. This function is the entry point of the program.Click to reveal answer
beginner
Why do we use
import statements in Go?We use
import statements to include other packages that provide useful functions and features, like fmt for printing output.Click to reveal answer
beginner
Show a simple Go program that prints "Hello, World!" and explain its parts.
Example:
<pre>package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}</pre>
- <code>package main</code>: declares this is an executable program
- <code>import "fmt"</code>: imports the package for printing
- <code>func main()</code>: the starting point of the program
- <code>fmt.Println</code>: prints the text to the screenClick to reveal answer
What keyword starts a Go program that can be run as an executable?
✗ Incorrect
The keyword
package main tells Go this program is executable and needs a main() function.Where does the Go program begin execution?
✗ Incorrect
Execution starts inside the
main() function.What is the purpose of the import statement in Go?
✗ Incorrect
Import statements bring in other packages that provide useful functions.
Which package is commonly imported to print output in Go?
✗ Incorrect
The
fmt package provides functions like Println to print text.What happens if you omit the main() function in a Go program with package main?
✗ Incorrect
A program with
package main must have a main() function or it will not compile.Describe the main parts of a simple Go program and their roles.
Think about what tells Go this is an executable, what brings in extra features, and where the program starts.
You got /4 concepts.
Explain why the main() function is important in Go programs with package main.
Consider what happens when you run a Go program.
You got /3 concepts.