December Code

Go for placements: interview questions by topic

Go is the language behind much of today's cloud infrastructure, from Docker and Kubernetes to countless internal services, and product companies and startups that build backends increasingly ask for it. It is a small language, which makes its interviews precise: with few features to cover, the questions go deep into how each one behaves. What does a slice share with the array it came from? When does a method need a pointer receiver? What does a function see when you pass it a map? What blocks, and what deadlocks?

The answers are rarely about syntax. They come from a few design decisions: values are copied, errors are ordinary return values, interfaces are satisfied without being declared, and concurrency is built from goroutines and channels rather than threads and locks. Knowing those decisions lets you predict what unfamiliar Go code does, which is what an interviewer is really checking.

The pages below take one topic each, with answers whose code was built and run with Go 1.27, and one question exactly as the diagnostic asks it. The diagnostic draws from every Go topic in the bank and names the ones to read first.

New to this? How to prepare for placements — the method — and what the readiness test measures.

Go topics, one page each

8 of the 8 Go topics in the bank have a page so far; the diagnostic draws from all 8.

  1. Go data types interview questions

    Go's types as interviews test them: the size of int, var versus :=, zero values, untyped constants, conversions, iota and shadowing.

  2. Go functions and defer interview questions

    Go functions as interviewers ask about them: multiple and named results, defer order and arguments, closures, variadic calls, pass by value.

  3. Go slices interview questions

    Go slices and arrays for interviews: arrays as values, the slice header, length and capacity, append growth, sharing, copying and removal.

  4. Go maps and strings interview questions

    Go maps and strings for interviews: creating maps, checking keys, iteration order, concurrent access, immutable strings, bytes, runes, builders.

  5. Go structs and methods interview questions

    Go structs as interviews test them: literals and pointers, value versus pointer receivers, constructors, embedding, struct tags, comparison.

  6. Go interfaces interview questions

    Go interfaces for interviews: implicit implementation, any, type switches and type assertions, compile-time checks, generics and method sets.

  7. Go error handling interview questions

    Go error handling explained: error values, custom error types, wrapping with %w, errors.Is and errors.As, errors.Join, panic and recover.

  8. Go goroutines and channels interview questions

    Goroutines and channels as Go interviews ask them: goroutines versus threads, buffered channels, close and range, select, races and deadlocks.

One question, exactly as the diagnostic asks it

From the Go bank — 30 questions across 8 topics. The answer is marked because this one is public; in a sitting you choose first, then see why each option is right or wrong.

Goroutines & Channels · easyGO-024

What happens when this Go code runs?

ch := make(chan int)
ch <- 1
fmt.Println(<-ch)
  1. 1It crashes: fatal error: all goroutines are asleep - deadlock!correct
  2. 2It prints 1
  3. 3It prints 0
  4. 4It does not compile: nothing receives from ch

An unbuffered channel has no storage: a send completes only when another goroutine is ready to receive at the same moment. Here main is the only goroutine, and it blocks on ch <- 1 before it ever reaches the receive on the next line. With every goroutine blocked, the Go runtime detects that nothing can make progress and stops the program with fatal error: all goroutines are asleep - deadlock!. It would print 1 with a buffered channel, make(chan int, 1), or with the send moved into its own goroutine. The compiler does not analyse channel usage, so it compiles.

More on this topic: Go goroutines and channels interview questions

Measure it

Reading the answers tells you what’s true. A diagnostic tells you what you get wrong.

10 Go questions across its topics, easy to hard, about fifteen minutes. You get a readiness figure with the arithmetic shown, the topics you missed named, and a practice set sized for today. Free: 1 diagnostic a month and 15 problems a day. No card.

By Harshit · updated