0% found this document useful (0 votes)
5 views2 pages

Golang Interview QA Level3

The document provides a collection of Golang interview questions and answers for candidates with over three years of experience, covering core language concepts and concurrency. Key topics include variable declaration differences, zero values of data types, defer statements, memory management, error handling, goroutines, channel types, and synchronization techniques. It emphasizes the importance of understanding Go's concurrency model and memory management for effective programming.

Uploaded by

krishnayt9080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Golang Interview QA Level3

The document provides a collection of Golang interview questions and answers for candidates with over three years of experience, covering core language concepts and concurrency. Key topics include variable declaration differences, zero values of data types, defer statements, memory management, error handling, goroutines, channel types, and synchronization techniques. It emphasizes the importance of understanding Go's concurrency model and memory management for effective programming.

Uploaded by

krishnayt9080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Golang Interview Questions and

Answers (3+ Years Experience)


Core Golang Language

What are the differences between var, const, and := in Go?


`var` declares a variable with optional initialization.
`const` declares an immutable constant.
`:=` is short-hand for declaring and initializing inside functions.
Example:
var x int = 5
const pi = 3.14
name := "Go"

What is the zero value of different Go data types?


int → 0
float64 → 0.0
string → ""
bool → false
Pointers, slices, maps, channels, interfaces → nil

What is a defer statement? When is it executed?


`defer` schedules a function call to run after the current function completes.
Used for cleanup like closing files or releasing locks.

Explain how Go handles memory management and garbage collection.


Go uses automatic garbage collection with a concurrent collector,
allowing efficient memory reuse without long pause times.

How do you handle error propagation in Go?


Check `err` after each function call.
Use `errors.New`, `fmt.Errorf`, `errors.Is`, and `errors.As` to handle errors.

Concurrency

What is a goroutine, and how is it different from a thread?


A goroutine is a lightweight thread managed by Go runtime.
It consumes less memory and is scheduled efficiently by Go.
What are buffered vs. unbuffered channels?
Unbuffered: sender and receiver wait for each other.
Buffered: can send/receive without waiting until full/empty.

Explain select in Go. How is it useful in concurrency?


`select` waits on multiple channel operations.
Used for multiplexing, timeouts, and non-blocking communication.

How do you avoid race conditions in Go?


Use `sync.Mutex`, channels, or `sync/atomic`.
Run code with `-race` flag to detect race conditions.

What does sync.WaitGroup do, and how is it used?


It waits for a group of goroutines to finish using `Add()`, `Done()`, and `Wait()`.

You might also like