0
0
Goprogramming~5 mins

Go program structure - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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 screen
Click to reveal answer
What keyword starts a Go program that can be run as an executable?
Astart main
Bfunc main
Cimport main
Dpackage main
Where does the Go program begin execution?
AInside the main() function
BAt the package declaration
CAt the first import statement
DAt the last line of code
What is the purpose of the import statement in Go?
ATo include external packages for extra features
BTo declare the program's package
CTo start the program
DTo define variables
Which package is commonly imported to print output in Go?
Aio
Bos
Cfmt
Dnet
What happens if you omit the main() function in a Go program with package main?
AThe program runs normally
BThe program will not compile
CThe program runs but does nothing
DThe program prints an error at runtime
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.