What is Go's approach to error handling?
Answer:
Go uses explicit error handling through multiple return values. Functions that might fail return an error as the last return value, which must be checked by the caller.
2. How does Go handle concurrent programming?
Answer:
Go uses goroutines and channels for concurrent programming. Goroutines are lightweight threads, and channels are used for communication between them.
3. What are Go interfaces?
Answer:
Interfaces in Go are a way to specify the behavior of an object. An interface type is defined by a set of methods.
4. Explain the difference between a slice and an array in Go.
Answer:
An array has a fixed size defined at compile-time, while a slice is a dynamically-sized, flexible view into the elements of an array.
5. How does Go's garbage collection work?
Answer:
Go uses a concurrent mark-and-sweep garbage collector that runs in the background to reclaim memory allocated to objects no longer in use.
6. How do you handle dependencies in Go projects?
Answer:
Dependencies in Go are managed using Go modules. You can create a module with go mod init, add dependencies with go get, and tidy up the module with go mod tidy.
7. What is a pointer in Go?
Answer:
A pointer holds the memory address of a value. Pointers are used to share memory and data between parts of a program.
8. How do you create a new goroutine?
Answer:
You can create a new goroutine by prefixing a function call with the go keyword, e.g., go myFunction().
9. What is a select statement in Go?