Go Lang Interview Questions


Go Lang Interview Questions and Answers

1. What is Go (Golang)?
Go is a statically typed, compiled programming language developed at Google, designed for simplicity, performance, and concurrency. It has a garbage collector and supports CSP-based concurrency using goroutines and channels.

2. What is the difference between concurrency and parallelism in Go?
Concurrency: Managing multiple tasks at the same time (not necessarily simultaneously).
Parallelism: Running tasks truly at the same time (requires multiple CPU cores).
Go uses goroutines for concurrency; parallelism depends on GOMAXPROCS.


3. How does Go’s garbage collector work?
Type: Concurrent, tri-color mark-and-sweep.
Runs alongside the program, marking reachable objects and freeing unreachable ones.
Minimizes pause times for better latency.

4. How does Go handle memory management without manual allocation/deallocation?
Automatic garbage collection.
Stack allocation for short-lived objects.
Escape analysis determines heap vs stack allocation.

5. How does Go's scheduler work?
M:N scheduler — M goroutines mapped to N OS threads.
Uses work stealing to balance load across threads.
Managed by G (goroutine), M (machine/OS thread), P (processor) model.

.

Comments