├── 1 ├── 1.go └── 1.txt ├── 2 ├── 2.go └── 2.txt ├── 3 └── 3.txt ├── 4 └── 4.txt ├── 5 └── 5.txt ├── 6 ├── 6.go └── 6.txt ├── 7 ├── 7.go └── 7.txt ├── 8 ├── 8.go └── 8.txt ├── 9 ├── 9.go └── 9.txt ├── 10 └── 10.txt ├── 11 └── 11.txt ├── 12 └── 12.txt ├── 13 └── 13.txt ├── 14 ├── 14.go └── 14.txt ├── 15 ├── 15.go └── 15.txt ├── 16 └── 16.txt ├── 17 ├── 17.go └── 17.txt ├── 18 └── 18.txt ├── 19 ├── 19.go └── 19.txt ├── 20 ├── 20.go └── 20.txt ├── 21 └── 21.txt ├── 22 └── 22.txt ├── 23 └── 23.txt ├── 24 └── 24.txt ├── 25 └── 25.txt ├── 26 ├── 26.go └── 26.txt ├── 27 └── 27.txt ├── 28 └── 28.txt ├── 29 ├── 29.go └── 29.txt ├── 30 └── 30.txt └── README.md /11/11.txt: -------------------------------------------------------------------------------- 1 | Q: Does Go support type inheritance? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: b 7 | -------------------------------------------------------------------------------- /24/24.txt: -------------------------------------------------------------------------------- 1 | Q: Does Go have a ternary operator? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: b 7 | -------------------------------------------------------------------------------- /8/8.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hi") 7 | } 8 | -------------------------------------------------------------------------------- /22/22.txt: -------------------------------------------------------------------------------- 1 | Q: Does Go support optional parameters in functions? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: b 7 | -------------------------------------------------------------------------------- /30/30.txt: -------------------------------------------------------------------------------- 1 | Q: In Go, does a *break* statement exit from a *select* block? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: a 7 | -------------------------------------------------------------------------------- /10/10.txt: -------------------------------------------------------------------------------- 1 | Q: What verb should we use with fmt.Printf to print boolean? 2 | 3 | a. %s 4 | b. %t 5 | c. %b 6 | 7 | A: b 8 | -------------------------------------------------------------------------------- /3/3.txt: -------------------------------------------------------------------------------- 1 | Q: Can short declaration ":=" be used for defining global variables? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: b 7 | -------------------------------------------------------------------------------- /25/25.txt: -------------------------------------------------------------------------------- 1 | Q: Is it possible to check if the slices are equal with "==" operator or not? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: b 7 | -------------------------------------------------------------------------------- /27/27.txt: -------------------------------------------------------------------------------- 1 | Q: What's the default buffer size of the channel in Go? 2 | 3 | a. 0 4 | b. 1 5 | c. No default size 6 | 7 | A: a 8 | -------------------------------------------------------------------------------- /15/15.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | for i := 0; i < 4; i++ { 7 | defer fmt.Print(i) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /6/6.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var ( 4 | aName string 5 | BigBro string 6 | 爱 string 7 | ) 8 | 9 | func main() { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /28/28.txt: -------------------------------------------------------------------------------- 1 | Q: What are the default values of these types: string, `*string` ? 2 | 3 | a. "", nil 4 | b. "", "" 5 | c. nil, nil 6 | d. nil, "" 7 | 8 | A: a 9 | -------------------------------------------------------------------------------- /29/29.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const array = []float32{0.1, 0.2, 0.3} 6 | 7 | func main() { 8 | fmt.Printf("%v", array) 9 | } 10 | -------------------------------------------------------------------------------- /9/9.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | var DEBUG bool 8 | 9 | func main() { 10 | fmt.Printf("DEBUG is %t\n", DEBUG) 11 | } 12 | -------------------------------------------------------------------------------- /16/16.txt: -------------------------------------------------------------------------------- 1 | Q: What characters does *go fmt* command use for indent? 2 | 3 | a. 4 spaces 4 | b. 2 spaces 5 | c. tab character 6 | d. it's configurable 7 | 8 | A: c 9 | -------------------------------------------------------------------------------- /12/12.txt: -------------------------------------------------------------------------------- 1 | Q: Is it possible to declare multiple types of variables in single declaration in Go? 2 | 3 | var a, b, c = 3, 4, "foo" 4 | 5 | a. Yes 6 | b. No 7 | 8 | A: a 9 | -------------------------------------------------------------------------------- /2/2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a int8 = 3 7 | var b int16 = 4 8 | 9 | sum := a + b 10 | 11 | fmt.Println(sum) 12 | } 13 | -------------------------------------------------------------------------------- /4/4.txt: -------------------------------------------------------------------------------- 1 | Q: Which one of the following is correct? 2 | 3 | a. const Pi = math.Pi 4 | b. const Pi = 3.14 5 | c. both a and b are correct 6 | d. None of the above 7 | 8 | A: c 9 | -------------------------------------------------------------------------------- /5/5.txt: -------------------------------------------------------------------------------- 1 | Q: Arrays are value types. In case of arrays perform as arguments, functions get their copies instead of a reference. Don’t they? 2 | 3 | a. Yes 4 | b. No 5 | 6 | A: a 7 | -------------------------------------------------------------------------------- /21/21.txt: -------------------------------------------------------------------------------- 1 | Q: What data types can you use "for - range" statement? 2 | 3 | a. array, slice, map 4 | b. array, slice, map, string, channel 5 | c. slice, map, string 6 | d. slice, map 7 | 8 | A: b 9 | -------------------------------------------------------------------------------- /13/13.txt: -------------------------------------------------------------------------------- 1 | Q: Is it possible to make package content directly accessible without need to be preceeded by "fmt."? 2 | 3 | a. Yes. import "fmt" 4 | b. Yes. import _ "fmt" 5 | c. Yes. import . "fmt" 6 | d. No 7 | 8 | A: c 9 | -------------------------------------------------------------------------------- /18/18.txt: -------------------------------------------------------------------------------- 1 | Q: How can we change the value of GOMAXPROCS in Go? 2 | 3 | a. Via environment variable GOMAXPROCS 4 | b. In the code 5 | c. a and b 6 | d. Impossible as it's equal to the number of available CPUs 7 | 8 | A: c 9 | -------------------------------------------------------------------------------- /23/23.txt: -------------------------------------------------------------------------------- 1 | Q: When will init() function be called? 2 | 3 | a. Before main() function in main package 4 | b. After importing a package with defined init() function 5 | c. Only when you call it 6 | d. a and b 7 | 8 | A: d 9 | -------------------------------------------------------------------------------- /26/26.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | import "unsafe" 5 | 6 | func main() { 7 | s := struct { 8 | A float32 9 | B string 10 | }{0, "go"} 11 | 12 | fmt.Printf("%T, %d\n", s, unsafe.Sizeof(s)) 13 | } 14 | -------------------------------------------------------------------------------- /1/1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const ( 6 | a = iota 7 | b = iota 8 | c = iota 9 | ) 10 | 11 | const ( 12 | d, e, f = iota, iota, iota 13 | ) 14 | 15 | func main() { 16 | fmt.Println(a, b, c, d, e, f) 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Preliminary information: 2 | 3 | * Each question has a separate folder and .txt file 4 | * Some questions have a code example in .go file 5 | * Each question has only one correct answer 6 | * All Questions have options from *a* to *d* 7 | -------------------------------------------------------------------------------- /14/14.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | func main() { 9 | type User struct { 10 | Name string `key:"name"` 11 | } 12 | 13 | u := User{} 14 | st := reflect.TypeOf(u) 15 | field := st.Field(0) 16 | fmt.Println(field.Tag.Get("key")) 17 | } 18 | -------------------------------------------------------------------------------- /15/15.txt: -------------------------------------------------------------------------------- 1 | Q: What is the output of the following code? 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | for i := 0; i < 4; i++ { 10 | defer fmt.Print(i) 11 | } 12 | } 13 | ``` 14 | 15 | a. 0123 16 | b. 3210 17 | c. 0000 18 | d. 3333 19 | 20 | A: b 21 | -------------------------------------------------------------------------------- /29/29.txt: -------------------------------------------------------------------------------- 1 | Q: Is it possible to define constant of an array type float32? 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | 8 | const array = []float32{0.1, 0.2, 0.3} 9 | 10 | func main() { 11 | fmt.Printf("%v", array) 12 | } 13 | ``` 14 | 15 | a. Yes 16 | b. No 17 | 18 | A: b 19 | -------------------------------------------------------------------------------- /20/20.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "os" 4 | 5 | func main() { 6 | src, err := os.Open("filename") 7 | // 1 8 | //defer src.Close() 9 | if err != nil { 10 | return 11 | } 12 | 13 | // 2 14 | //defer src.Close() 15 | 16 | src.WriteString("Hello") 17 | 18 | // 3 19 | //defer src.Close() 20 | } 21 | -------------------------------------------------------------------------------- /8/8.txt: -------------------------------------------------------------------------------- 1 | Q: How to compile the following code to the binary file with name "eight"? 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | fmt.Println("Hi") 10 | } 11 | ``` 12 | 13 | a. go build 8.go eight 14 | b. go build -o eight 8.go 15 | c. go build 8.go -o eight 16 | 17 | A: b 18 | -------------------------------------------------------------------------------- /9/9.txt: -------------------------------------------------------------------------------- 1 | Q: Can we set DEBUG=true with *go build*? 2 | 3 | ```go 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | ) 9 | 10 | var DEBUG bool 11 | 12 | func main() { 13 | fmt.Printf("DEBUG is %t\n", DEBUG) 14 | } 15 | ``` 16 | 17 | a. Yes. go build -ldflags '-X main.DEBUG=true' 9/9.go 18 | b. No 19 | 20 | A: b 21 | -------------------------------------------------------------------------------- /17/17.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | tagsViews := map[string]int{ 7 | "unix": 0, 8 | "python": 1, 9 | "go": 2, 10 | "golang": 3, 11 | "devops": 4, 12 | "gc": 5, 13 | } 14 | for key, views := range tagsViews { 15 | fmt.Println("There are", views, "views for", key) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /6/6.txt: -------------------------------------------------------------------------------- 1 | Q: Which of the following variables are exportable from another external package? 2 | 3 | ```go 4 | package main 5 | 6 | var ( 7 | aName string 8 | BigBro string 9 | 爱 string 10 | ) 11 | 12 | func main() { 13 | 14 | } 15 | ``` 16 | 17 | a. aName, BigBro 18 | b. BigBro 19 | c. aName, BigBro, 爱 20 | d. BigBro, 爱 21 | 22 | A: b 23 | -------------------------------------------------------------------------------- /7/7.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | func main() { 9 | var wg sync.WaitGroup 10 | 11 | wg.Add(1) 12 | go func() { 13 | fmt.Println("1") 14 | wg.Done() 15 | }() 16 | 17 | wg.Add(1) 18 | go func() { 19 | fmt.Println("2") 20 | wg.Done() 21 | }() 22 | 23 | wg.Wait() 24 | fmt.Println("3") 25 | } 26 | -------------------------------------------------------------------------------- /2/2.txt: -------------------------------------------------------------------------------- 1 | Q: What's the output of the following code? 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | var a int8 = 3 10 | var b int16 = 4 11 | 12 | sum := a + b 13 | 14 | fmt.Println(sum) 15 | } 16 | ``` 17 | 18 | a. 7 19 | b. 4 20 | c. 3 21 | d. invalid operation: a + b (mismatched types int8 and int16) 22 | 23 | A: d 24 | -------------------------------------------------------------------------------- /1/1.txt: -------------------------------------------------------------------------------- 1 | Q: What's the output of the following code? 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | 8 | const ( 9 | a = iota 10 | b = iota 11 | c = iota 12 | ) 13 | 14 | const ( 15 | d, e, f = iota, iota, iota 16 | ) 17 | 18 | func main() { 19 | fmt.Println(a, b, c, d, e, f) 20 | } 21 | ``` 22 | 23 | a. 0 1 2 3 4 5 24 | b. 0 1 2 0 1 2 25 | c. 0 1 2 0 0 0 26 | d. 0 0 0 0 1 2 27 | 28 | A: c 29 | -------------------------------------------------------------------------------- /26/26.txt: -------------------------------------------------------------------------------- 1 | Q: What is the size of the following struct? 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | import "unsafe" 8 | 9 | func main() { 10 | s := struct { 11 | A float32 12 | B string 13 | }{0, "go"} 14 | 15 | fmt.Printf("%T, %d\n", s, unsafe.Sizeof(s)) 16 | } 17 | ``` 18 | 19 | a. 12 20 | b. 8 21 | c. 12 bytes on architectures with 4 bytes pointers and 24 on architectures with 8 bytes pointers 22 | d. 24 23 | 24 | A: c 25 | -------------------------------------------------------------------------------- /20/20.txt: -------------------------------------------------------------------------------- 1 | Q: Where should we use *defer* in the following code? 2 | 3 | ```go 4 | package main 5 | 6 | import "os" 7 | 8 | func main() { 9 | src, err := os.Open("filename") 10 | // 1 11 | //defer src.Close() 12 | if err != nil { 13 | return 14 | } 15 | 16 | // 2 17 | //defer src.Close() 18 | 19 | src.WriteString("Hello") 20 | 21 | // 3 22 | //defer src.Close() 23 | } 24 | ``` 25 | 26 | a. 1 27 | b. 2 28 | c. 3 29 | d. None of them 30 | 31 | A: b 32 | -------------------------------------------------------------------------------- /19/19.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | // 1 11 | s := "" 12 | for i := 0; i < 10; i++ { 13 | s += "a" 14 | } 15 | fmt.Println(s) 16 | 17 | // 2 18 | var buffer bytes.Buffer 19 | for i := 0; i < 10; i++ { 20 | buffer.WriteString("a") 21 | } 22 | fmt.Println(buffer.String()) 23 | 24 | // 3 25 | sl := []string{"a", "a", "a", "a", "a", "a", "a", "a", "a", "a"} 26 | fmt.Printf(strings.Join(sl, "")) 27 | } 28 | -------------------------------------------------------------------------------- /7/7.txt: -------------------------------------------------------------------------------- 1 | Q: What's the sequence for the output of the following code? 2 | 3 | ```go 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "sync" 9 | ) 10 | 11 | func main() { 12 | var wg sync.WaitGroup 13 | 14 | wg.Add(1) 15 | go func() { 16 | fmt.Println("1") 17 | wg.Done() 18 | }() 19 | 20 | wg.Add(1) 21 | go func() { 22 | fmt.Println("2") 23 | wg.Done() 24 | }() 25 | 26 | wg.Wait() 27 | fmt.Println("3") 28 | } 29 | ``` 30 | 31 | a. Always 1 2 3 32 | b. Always 2 1 3 33 | c. 3 34 | d. "1 2 3" or "2 1 3" 35 | 36 | A: d 37 | -------------------------------------------------------------------------------- /14/14.txt: -------------------------------------------------------------------------------- 1 | Q: Is it possible to have multiple tag strings in struct field? 2 | 3 | ```go 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "reflect" 9 | ) 10 | 11 | func main() { 12 | type User struct { 13 | Name string `key:"name"` 14 | } 15 | 16 | u := User{} 17 | st := reflect.TypeOf(u) 18 | field := st.Field(0) 19 | fmt.Println(field.Tag.Get("key")) 20 | } 21 | ``` 22 | 23 | a. Yes. They should be comma-separated: `key:"name",maxlength:"128"` 24 | b. Yes. They should be space-separated: `key:"name" maxlength:"128"` 25 | c. No 26 | 27 | A: b 28 | -------------------------------------------------------------------------------- /17/17.txt: -------------------------------------------------------------------------------- 1 | Q: Choose the correct statement regarding the output of the following code. 2 | 3 | ```go 4 | package main 5 | 6 | import "fmt" 7 | 8 | func main() { 9 | tagsViews := map[string]int{ 10 | "unix": 0, 11 | "python": 1, 12 | "go": 2, 13 | "golang": 3, 14 | "devops": 4, 15 | "gc": 5, 16 | } 17 | for key, views := range tagsViews { 18 | fmt.Println("There are", views, "views for", key) 19 | } 20 | } 21 | ``` 22 | 23 | a. Output will be ordered by values 24 | b. Output will be ordered by keys 25 | c. Output will be ordered randomly 26 | d. Output will be ordered by position in the code 27 | 28 | A: c 29 | -------------------------------------------------------------------------------- /19/19.txt: -------------------------------------------------------------------------------- 1 | Q: Which is the slowest concatenation method from the list? 2 | 3 | ```go 4 | package main 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | // 1 14 | s := "" 15 | for i := 0; i < 10; i++ { 16 | s += "a" 17 | } 18 | fmt.Println(s) 19 | 20 | // 2 21 | var buffer bytes.Buffer 22 | for i := 0; i < 10; i++ { 23 | buffer.WriteString("a") 24 | } 25 | fmt.Println(buffer.String()) 26 | 27 | // 3 28 | sl := []string{"a", "a", "a", "a", "a", "a", "a", "a", "a", "a"} 29 | fmt.Printf(strings.Join(sl, "")) 30 | } 31 | ``` 32 | 33 | a. 1 34 | b. 2 35 | c. 3 36 | 37 | A: a 38 | --------------------------------------------------------------------------------