update: quizzes for 2nd 4th secs

This commit is contained in:
Inanc Gumus
2019-05-03 17:29:16 +03:00
parent f3bf95e66c
commit c39f15cb68
4 changed files with 30 additions and 37 deletions

View File

@ -1,19 +1,19 @@
## Where you should put your Go source code into? ## Where should you save your Go source code?
* Anywhere on my computer * Anywhere on my computer
* Under $GOPATH * Under $GOPATH
* Under $GOPATH/src *CORRECT* * Under $GOPATH/src *CORRECT*
## What $GOPATH means? ## What does $GOPATH mean?
* It's a file for Go runtime * It's a file for Go runtime
* Stores Go source code files and compiled packages * Stores Go source code files and compiled packages
* It's a path for gophers to follow * It's a path for gophers to follow
## Do you need to set your $GOPATH? ## Do you need to set $GOPATH?
* Yes * Yes
* No: It's stored on my desktop * No: It's stored on my desktop
* No: It's stored under my user path *CORRECT* * No: It's stored under my user path *CORRECT*
## How can you print your $GOPATH? ## How can you print $GOPATH?
* Using `ls` command * Using `ls` command
* Using `go env GOPATH` command *CORRECT* * Using `go env GOPATH` command *CORRECT*
* Using `go environment` command * Using `go environment` command

View File

@ -1,4 +1,4 @@
## Which keyword below defines a new package for the following program? ## Which keyword below that you need use to define a package?
```go ```go
package main package main
@ -10,33 +10,33 @@ func main() {
3. fmt.Println 3. fmt.Println
4. import 4. import
> **1:** This keyword is used to declare a new function. > **1:** func keyword is used to declare a new function.
> >
> >
> **2:** That's right! package keyword allows you to define which package a Go file belongs to. > **2:** That's right! package keyword allows you to define a package for a Go file.
> >
> >
> **3:** This is not a keyword. It's the Println function of the fmt package. > **3:** It's not a keyword, it's a function of the fmt package.
> >
> >
> **4:** This keyword is used to import a package. > **4:** import keyword is used to import a package.
> >
> >
## Why `package main` is used in the following program? ## What is the purpose of using package main in the following program?
```go ```go
package main package main
func main() { func main() {
} }
``` ```
* It creates a library package * To create a library package
* It allows us to properly exit from this program * To properly exit from the program
* It creates an executable Go program *CORRECT* * To create an executable Go program *CORRECT*
## Why `func main` is used in the following program? ## What is the purpose of func main in the following program?
```go ```go
package main package main
@ -44,21 +44,21 @@ func main() {
} }
``` ```
1. It defines a package called main 1. It defines a package called main
2. It allows Go to start executing this program by using the code inside func main *CORRECT* 2. It allows Go to start executing the program *CORRECT*
3. It prints a message to the console 3. It prints a message to the console
> **1:** main function doesn't create a package. > **1:** main function doesn't create a package.
> >
> >
> **2:** That's right. Go automatically calls the main function to execute your program. > **2:** That's right. Go automatically calls the main function to execute a program.
> >
> >
> **3:** It doesn't print anything at least directly. > **3:** It doesn't print anything (at least directly).
> >
> >
## Why `import "fmt"` is used in the following program? ## What is the purpose of import "fmt" in the following program?
```go ```go
package main package main
import "fmt" import "fmt"
@ -133,7 +133,7 @@ _(except the main func)_
> >
## What the following program does? ## What does the following program print?
```go ```go
package main package main
@ -141,14 +141,14 @@ func main() {
} }
``` ```
1. It prints a message to the console 1. It prints a message to the console
2. It's a correct program and it doesn't print anything *CORRECT* 2. It's a correct program but it doesn't print anything *CORRECT*
3. It's an incorrect program 3. It's an incorrect program
> **1:** It doesn't print a message. To do that you can use fmt.Println function. > **1:** It doesn't print a message. To do that you can use fmt.Println function.
> >
> >
> **2:** Yes, it's a correct program but since it doesn't contain fmt.Println it doesn't print anything. > **2:** Yes, it's a correct program, however since it doesn't contain fmt.Println it doesn't print anything.
> >
> >

View File

@ -1,4 +1,4 @@
## What's the difference between `go build` and `go run`? ## What is the difference between `go build` and `go run`?
1. `go run` just compiles a program; whereas `go build` both compiles and runs it. 1. `go run` just compiles a program; whereas `go build` both compiles and runs it.
2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT* 2. `go run` both compiles and runs a program; whereas `go build` just compiles it. *CORRECT*
@ -10,7 +10,7 @@
> >
## Which directory `go build` puts the compiled code into? ## Go saves the compiled code in a directory. What is the name of that directory?
1. The same directory where you call `go build` *CORRECT* 1. The same directory where you call `go build` *CORRECT*
2. $GOPATH/src directory 2. $GOPATH/src directory
3. $GOPATH/pkg directory 3. $GOPATH/pkg directory
@ -24,24 +24,17 @@
> >
## Which directory `go run` puts the compiled code into? ## Which is true for runtime?
1. The same directory where you call `go run`
2. $GOPATH/src directory
3. $GOPATH/pkg directory
4. Into a temporary directory. *CORRECT*
## Which one below is true for runtime?
1. It happens when your program starts running on a computer *CORRECT* 1. It happens when your program starts running on a computer *CORRECT*
2. It happens while your program is being compiled 2. It happens while your program is being compiled
## Which one below is true for the compile-time? ## Which is true for the compile-time?
1. It happens when your program starts running on a computer 1. It happens when your program starts running on a computer
2. It happens while your program is being compiled *CORRECT* 2. It happens while your program is being compiled *CORRECT*
## In which stage your program can print a message to the console? ## When can a Go program print a message to the console?
1. While it's being compiled. 1. While it's being compiled.
2. While it runs (after compile-time). *CORRECT* 2. While it runs (after compile-time). *CORRECT*
3. While it runs (inside the compile-time). 3. While it runs (inside the compile-time).

View File

@ -48,7 +48,7 @@
> >
## Why the following code doesn't work? ## Why doesn't the following program work?
```go ```go
package main package main
import "fmt" import "fmt"
@ -63,7 +63,7 @@ func main() {
3. By moving "Hello" out of the func main. 3. By moving "Hello" out of the func main.
## Does the following code works? And why? ## Does the following program work?
```go ```go
package main package main
import ( import (
@ -91,7 +91,7 @@ func main() {
> >
## Why this code works? ## Why does this program work?
```go ```go
package main package main
import ( import (