0
0
Goprogramming~5 mins

Channel creation in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a channel in Go?
A channel in Go is a way to send and receive values between different goroutines safely and synchronously.
Click to reveal answer
beginner
How do you create an unbuffered channel of integers in Go?
Use make(chan int) to create an unbuffered channel that sends and receives integers.
Click to reveal answer
intermediate
What is the difference between buffered and unbuffered channels?
Unbuffered channels block the sender until the receiver is ready. Buffered channels allow sending a limited number of values without blocking.
Click to reveal answer
beginner
How do you create a buffered channel with capacity 3 for strings?
Use make(chan string, 3) to create a buffered channel that can hold 3 strings without blocking the sender.
Click to reveal answer
intermediate
Why should channels be created before using them?
Channels must be created with make before use because they are references to data structures that manage communication. Using a nil channel causes deadlock.
Click to reveal answer
How do you create an unbuffered channel of type int in Go?
Achan int{}
Bmake(chan int)
Cnew(chan int)
Dchan int()
What happens when you send to an unbuffered channel with no receiver ready?
AThe send fails immediately
BThe program crashes
CThe send is ignored
DThe send blocks until a receiver is ready
How do you create a buffered channel with capacity 5 for float64 values?
Achan float64(5)
Bmake(chan float64)
Cmake(chan float64, 5)
Dnew(chan float64, 5)
What is the default value of a channel variable before creation?
Anil
Bempty channel
Czero value of element type
Dfalse
Which keyword is used to create a channel in Go?
Amake
Bnew
Cchan
Dcreate
Explain how to create both unbuffered and buffered channels in Go and when you might use each.
Think about how channels control communication between goroutines.
You got /6 concepts.
    Describe what happens if you try to send or receive on a nil channel in Go.
    Consider what happens when a channel is not initialized.
    You got /4 concepts.