Golang's 100 questions compiled
Ability model (test)
Primary primary:
Familiar with basic syntax and able to understand the intention of the code;
Under the guidance of others, the code written complies with the CleanCode specification;
Intermediate:
Ability to independently complete the development and testing of user stories;
Ability to smell the bad smell of code and know how to refactor it to achieve your goal;
Advanced senior:
Ability to develop high-quality and high-performance code;
Ability to proficient in using advanced features, develop programming or testing frameworks;
Fill in the blanks
1.【Junior】Declare an integer variable i___________
Reference answer: var i int
2. [Elementary] Declare an integer array a______________ with 10 elements
Reference answer: var a [10]int
3. [Junior] Declare an integer array slice s___________
Reference answer: var s []int
4. [Junior] Declare an integer pointer variable p___________
Reference answer: var p *int
5.【Junior】Declare a map variable m___________ with a key as a string value as an integer
Reference answer: var m map[string]int
6. [Elementary] Declare a function variable f___________ with both input parameters and return values as integers
Reference answer: var f func(a int) int
7.【Junior】Declare a one-way channel variable ch________________________
Reference answer: var ch <-chan int
8. [Junior] Assuming that the name of the source file is, the name of the test file is __________
Reference answer: slice_test.go
9.【Junior】go test requires that the prefix of the test function must be named ___________
Reference answer: Test
10. [Elementary] The keyword to start a goroutine is __________
Reference answer: go
Judgment question
1.【Junior】Array is a value type ()
Reference answer: T
2.【Junior level】Use map without introducing any library ()
Reference answer: T
3. [Intermediate] Built-in function delete can delete elements in an array slice ()
Reference answer: F
4. [Junior] Pointer is the basic type ()
Reference answer: F
5. [Junior] interface{} is Any type () that can point to any object.
Reference answer: T
6. [Intermediate] The following code about file operations may trigger exceptions ()
file, err := ("") defer () if err != nil { ("open file failed:",err) return } ...
Reference answer: T
7. [Elementary] Golang does not support automatic garbage collection ()
Reference answer: F
8. [Elementary] Golang supports reflection. The most common use scenario for reflection is to serialize objects ()
Reference answer: T
9. [Elementary] Golang can reuse C/C++ modules, and this function is called Cgo()
Reference answer: F
10. [Elementary] The code between two slant points in the following code, such as json:"x", is used to use x as the name when the X field is encoded from the structure instance to the JSON data format. This can be regarded as a renaming method ()
type Position struct { X int `json:"x"` Y int `json:"y"` Z int `json:"z"` }
Reference answer: T
11. [Elementary] Determines the scope of member variables or function first letters ()
Reference answer: T
12. [Junior] For constant definition zero(const zero = 0.0), zero is a floating point constant()
Reference answer: F
13. [Junior] The inverse operation of variable x is ~x()
Reference answer: F
14. [Elementary] The running result of the following program is xello()
func main() { str := "hello" str[0] = 'x' (str) }
Reference answer: F
15. [Elementary] golang supports goto statement ()
Reference answer: T
16. [Elementary] The pointer p in the following code is a wild pointer, because the returned stack will be released when the function ends ()
type TimesMatcher struct { base int } func NewTimesMatcher(base int) *TimesMatcher{ return &TimesMatcher{base:base} } func main() { p := NewTimesMatcher(3) ... }
Reference answer: F
17. [Junior] Anonymous functions can be assigned directly to a variable or executed directly ()
Reference answer: T
18. [Elementary] If the caller calls a method with multiple return values, but does not want to care about one of the return values, you can simply use an underscore "_" to skip this return value. The variable corresponding to the underscore is called anonymous variable ()
Reference answer: T
19. [Elementary] In the multi-return value of a function, if there is an error or bool type, it is generally placed in the last one ()
Reference answer: T
20. [Elementary] Errors are part of the business process, and exceptions are not ()
Reference answer: T
21. [Elementary] When executing a function, if an exception is caused by panic, the delayed function will not be executed ()
Reference answer: F
22. [Intermediate] When the program is running, if you encounter situations such as referring to a null pointer, subscript out of bounds, or explicitly calling the panic function, the execution of the panic function will be triggered first, and then the delay function will be called.
The caller continues to pass panic, so the process keeps repeating in the call stack: the function stops executing, and the call delayed execution of the function.
If there is no call to recover function in the delay function, the starting point of the Ctrip will be reached, the Ctrip will end, and then terminate all other Ctrip. The other Ctrip's termination process will also occur repeatedly:
The function stops execution and calls the delayed execution function ()
Reference answer: F
23. [Junior] The package name of the same level file does not allow multiple ()
Reference answer: T
24. [Intermediate] You can add corresponding methods to any type ()
Reference answer: F
25. [Elementary] Although golang does not explicitly provide inheritance syntax, it realizes inheritance () through anonymous combination.
Reference answer: T
26. [Elementary] The order of each iteration when iterating a map using for range may be different, because the iteration of the map is random ()
Reference answer: T
27. [Elementary] The switch can be followed by no expression ()
Reference answer: T
28. [Intermediate] The non-exported variables (variable names starting with lowercase letters) will not be encoded when serialized, so when decoded, the values of these non-exported variables are zero values of their type ()
Reference answer: T
29. [Elementary] There is no concept of a constructor in golang. The creation of an object is usually completed by a global creation function, named after NewXXX ()
Reference answer: T
30. [Intermediate] The channel itself must support read and write at the same time, so there is no one-way channel()
Reference answer: F
The above is the detailed content of the Go classic interview questions summary (fill in the blanks + judgment). For more information about Go classic interview questions, please pay attention to my other related articles!