02-write-your-first-program/questions/02-code-your-first-program/README.md
package main
func main() {
}
1: func keyword is used to declare a new function.
2: That's right! package keyword allows you to define a package for a Go file.
3: It's not a keyword, it's a function of the fmt package.
4: import keyword is used to import a package.
package main
func main() {
}
package main
func main() {
}
1: main function doesn't create a package.
2: That's right. Go automatically calls the main function to execute a program.
3: It doesn't print anything (at least directly).
package main
import "fmt"
func main() {
fmt.Println("Hi!")
}
fmt package; so you can use its functionalities CORRECT1:
fmt.Printlnprints a message not theimport "fmt".2:
packagekeyword does that, not theimportkeyword.3: Yes. For example, after you import the fmt package you can call its Println function to print a message to the console.
2: Go looks for package main and func main to do that. A function doesn't do that on its own.
3:
importkeyword does that.4: For example:
fmt.Printlndoes that.
1: No, you don't need to call the main function. Go automatically executes it.
(except the main func)
1: That's right. You need to call a function yourself. Go won't execute it automatically. Go only calls the main function automatically (and some other functions which you didn't learn about yet).
2: That's only the job of the
func main. There's only onefunc main.
3: Go doesn't call any function automatically except the main func (and some other functions which you didn't learn about yet). So, except the main func, you need to call the functions yourself.
package main
func main() {
}
1: It doesn't print a message. To do that you can use fmt.Println function.
2: Yes, it's a correct program, however since it doesn't contain fmt.Println it doesn't print anything.
3: It's a correct program. It uses the package keyword and it has a main function. So, this is a valid and an executable Go program.
package main
func main() {
fmt.Println(Hi! I want to be a Gopher!)
}
1: It doesn't pass the message to Println wrapped between double-quotes. It should be like: fmt.Println("Hi! I want to be a Gopher")
3: It doesn't import "fmt" package. Also see #1.
package main
import "fmt"
func main() {
fmt.Println("Hi there!")
}
Println2: import "fmt" imports the
fmtpackage; so you can use its functionalities.3: Actually, this program is correct.