Go

Give the complete table of channel operation behavior for nil, open, and closed channels.

Question 185MediumGo 1.22 to 1.25
Operationnil channelopen channelclosed channel
send ch <- vblocks foreverblocks until received/buffer spacepanic
receive <-chblocks foreverblocks until valuedrains buffer, then zero value, ok=false
close(ch)panicsucceedspanic
len/cap0queued / capacityremaining queued / capacity

What the interviewer is looking for: you should know all three panics (send on closed, close of nil, double close) and understand that "blocks forever" on nil is a feature that select uses to turn cases off dynamically. Candidates often say that receiving from a closed channel panics. It does not. It returns buffered values first and then zero values forever.

More on Channels & select

All 38 Channels & select questions