All interview guides

Go Interview Questions and Answers

24 questions that come up in Go technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is a goroutine?

Intermediate

Answer: All of the above

A goroutine is a lightweight thread managed by the Go runtime. Start with `go functionName()`. Goroutines are much cheaper than OS threads.

2. What is Go (Golang)?

Beginner

Answer: An open-source programming language created by Google

Go (or Golang) is an open-source, statically typed, compiled programming language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson.

3. What is the reflect package?

Advanced

Answer: All of the above

reflect package provides runtime reflection, allowing inspection and manipulation of types and values. Powerful but comes with performance cost.

4. What is a channel in Go?

Intermediate

Answer: All of the above

Channels are typed conduits for communication between goroutines. Created with make: `ch := make(chan int)`. Send with `ch <- value`, receive with `value := <-ch`.

5. What is reflect.Type vs reflect.Value?

Advanced

Answer: All of the above

reflect.Type represents type information, reflect.Value represents runtime value. Get with reflect.TypeOf() and reflect.ValueOf().

6. What is unsafe package?

Advanced

Answer: All of the above

unsafe package contains operations that bypass Go type safety. Enables pointer arithmetic, arbitrary type conversion. Use sparingly for performance-critical code.

7. What is a buffered channel?

Intermediate

Answer: All of the above

Buffered channels have a capacity: `make(chan int, 100)`. Sends block only when buffer is full, receives block when empty.

8. What is the correct package declaration for a main program?

Beginner

Answer: package main

Every Go program that produces an executable must declare `package main` at the top. The main package is special - it defines a standalone executable.

9. What is escape analysis?

Advanced

Answer: All of the above

Escape analysis determines whether variable is allocated on stack or heap. Variables escaping function scope go to heap. Use `go build -gcflags=-m` to see.

10. What is the entry point function in Go?

Beginner

Answer: main()

The main() function is the entry point of a Go program. It must be in the main package and takes no arguments and returns nothing.

11. What does close() do with channels?

Intermediate

Answer: All of the above

close(ch) closes a channel, indicating no more values will be sent. Receivers can still receive remaining values. Test with `val, ok := <-ch`.

12. What is inlining?

Advanced

Answer: All of the above

Inlining replaces function calls with the function body. Reduces call overhead. Compiler automatically inlines small functions. Control with //go:noinline.

13. What is the select statement used for?

Intermediate

Answer: Both b and c

select lets a goroutine wait on multiple channel operations. It blocks until one case can proceed, then executes that case. Similar to switch for channels.

14. How do you declare a variable in Go?

Beginner

Answer: Both a and b

Go has two ways to declare variables: `var name type` (explicit type) and `name := value` (short declaration with type inference, only inside functions).

15. What is the race detector?

Advanced

Answer: All of the above

Race detector finds data races at runtime. Run with `go test -race` or `go run -race`. Detects unsynchronized access to shared variables.

16. What does := do in Go?

Beginner

Answer: Short variable declaration with type inference

The := operator is a short variable declaration that infers the type from the right-hand side. It can only be used inside functions.

17. What is an interface in Go?

Intermediate

Answer: All of the above

An interface is a set of method signatures. Types implement interfaces implicitly by implementing the methods. Enables polymorphism and abstraction.

18. Which of these is NOT a basic type in Go?

Beginner

Answer: char

Go does not have a char type. Characters are represented using rune (alias for int32) or byte (alias for uint8). Basic types include int, float64, string, bool.

19. What is the empty interface?

Intermediate

Answer: All of the above

The empty interface `interface{}` has no methods, so all types implement it. Can hold any value. Go 1.18+ prefers `any` as alias.

20. What is the memory model?

Advanced

Answer: All of the above

Go memory model specifies conditions under which reads/writes are visible across goroutines. Defines happens-before relationships and synchronization.

21. What is pprof?

Advanced

Answer: All of the above

pprof profiles running Go programs. Provides CPU, memory, goroutine, and blocking profiles. Essential for performance optimization.

22. How do you create a constant in Go?

Beginner

Answer: const name = value

Constants are declared using the `const` keyword: `const Pi = 3.14`. Constants must be assigned at compile time and cannot be changed.

23. What is type assertion?

Intermediate

Answer: All of the above

Type assertion extracts the underlying concrete value from an interface: `value, ok := i.(string)`. Use ok to check success.

24. What is the atomic package?

Advanced

Answer: All of the above

sync/atomic provides low-level atomic memory operations. Enables lock-free synchronization for simple operations like counters. Faster than mutexes for simple cases.

Ready to test yourself?

The full Go bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Go quiz