Order of writing

Report a typo

Below is a Go program that creates three data writing channels and uses a select statement to write data to one of them. Analyze the code and determine in which channel the data will be written.

package main

import "fmt"

func main() {
    chan1 := make(chan int, 1)
    chan2 := make(chan int, 1)
    chan3 := make(chan int, 1)

    select {
    case chan1 <- 1:
        fmt.Println("The data is written to the first channel.")
    case chan2 <- 2:
        fmt.Println("The data is written to the second channel.")
    case chan3 <- 3:
        fmt.Println("The data is written to the third channel.")
    }

    close(chan1)
    close(chan2)
    close(chan3)
}
Select one option from the list
___

Create a free account to access the full topic