Go course

ChannelsQuiz: Channels

Go

Display

Theme

Channels · Quiz

Quiz: Channels

Test what you know about goroutines, unbuffered and buffered channels, close, range, select, sync.WaitGroup, and deadlock. Answer every question in the panel on the right.

  1. Question 1 of 6What happens when this program runs?
    func main() {
    	ch := make(chan int)
    	ch <- 1
    	fmt.Println(<-ch)
    }
  2. Question 2 of 6What if the channel in the previous question were created with make(chan int, 1)?
  3. Question 3 of 6When does the loop for v := range ch stop?
  4. Question 4 of 6Which operation causes a panic?
  5. Question 5 of 6The function func catat(log chan<- string) takes a parameter of type chan<- string. What does that mean?
  6. Question 6 of 6What does the default case do in a select?
    select {
    case antrean <- p:
    	fmt.Println("masuk")
    default:
    	fmt.Println("penuh")
    }