Complete the code to create a channel of integers.
ch := make([1])Channels in Go are created using make(chan Type). Here, chan int creates a channel for integers.
Complete the code to send the value 5 into the channel.
ch := make(chan int)
go func() {
ch [1] 5
}()To send a value into a channel, use ch <- value. The arrow points from the value to the channel.
Fix the error in receiving a value from the channel.
ch := make(chan int)
go func() {
ch <- 10
}()
value := [1] chTo receive a value from a channel, use <- ch. The arrow points from the channel to the variable.
Fill both blanks to create a channel and send a value.
var [1] [2] [1] = make(chan string) go func() { [1] <- "hello" }()
First, declare a variable messages of type chan string. Then create the channel with make(chan string).
Fill all three blanks to receive a value from the channel and print it.
ch := make(chan int)
go func() {
ch <- 42
}()
value := [1] ch
fmt.[2]("Received: %d\n", [3])Use value := <- ch to receive from the channel. Then print with fmt.Printf and pass value as argument.