0
0
Goprogramming~10 mins

Buffered and unbuffered channels in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an unbuffered channel of integers.

Go
ch := make(chan [1])
Drag options to blanks, or click blank then click option'
Achan int
Bbuffered
Cstring
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'buffered' as a type is invalid.
Using 'chan int' inside make is incorrect syntax.
2fill in blank
medium

Complete the code to create a buffered channel with capacity 3.

Go
ch := make(chan int, [1])
Drag options to blanks, or click blank then click option'
A0
B1
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 creates an unbuffered channel.
Using 1 or 5 does not match the required capacity.
3fill in blank
hard

Fix the error in sending a value to an unbuffered channel without a receiver.

Go
ch := make(chan int)
// Send value without receiver
ch [1] 10
Drag options to blanks, or click blank then click option'
A<-chan
B<-
C<-chan<-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<-' alone without channel causes syntax error.
Using '<-chan' or '<-chan<-' is invalid syntax.
4fill in blank
hard

Fill both blanks to create a buffered channel and send a value without blocking.

Go
ch := make(chan int, [1])
ch [2] 5
Drag options to blanks, or click blank then click option'
A3
B<-
C<-chan
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 capacity makes channel unbuffered, causing blocking.
Using '<-chan' is invalid for sending.
5fill in blank
hard

Fill all three blanks to receive a value from a buffered channel and print it.

Go
ch := make(chan int, [1])
ch <- 42
value [2] [3] ch
fmt.Println(value)
Drag options to blanks, or click blank then click option'
A1
B:=
C<-
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using capacity 1 may work but does not match the problem.
Using '=' instead of ':=' causes compile error.
Using '<-' after variable name is wrong.