Go Multiple Choice Questions and answers | Go Online quiz - Part 06

These Go Programming MCQs(Multiple Choice Question) are designed to prepare for interview preparation and checking the knowledge about Go. These questions are taken from many sources and i hope these quizzes help to check your fundamental about Go.



Go Multiple Choice Questions and Answers

 

1. what is the output of below code snippet

package main

import (
        "fmt"
)

func PrintHello() {
        fmt.Println("Hello")
}

func main() {
        go PrintHello()
        fmt.Println("User")
}




 

2. what is the output of below code snippet

package main

import (
        "fmt"
)

func main() {
        ch := make(chan int)
        ch <- 2
        get := <-ch
        fmt.Println(get)
}




 

3. what is the output of below code snippet?

package main

import (
        "fmt"
)

func printChannel(ch chan int){
        fmt.Println(<-ch)
}

func main() {
        ch := make(chan int)
        ch <- 2
        go printChannel(ch)
        fmt.Println("Done")
}




 

4. What is the output of below code snippet?

package main

import (
        "fmt"
)

func printChannel(ch chan int){
        fmt.Println(<-ch)
}

func main() {
        ch := make(chan int,1)
        ch <- 2
        go printChannel(ch)
        fmt.Println("Done")
}




 

5. What is the output of below code snippet?

package main

import (
        "fmt"
)

func printChannel(ch chan int) {
        fmt.Println(<-ch)
        fmt.Println(<-ch)
}

func main() {
        ch := make(chan int)
        go printChannel(ch)
        ch <- 2
        ch <- 3
        fmt.Println("Done")
}




 

6. What is the output of below code snippet?

package main

import (
        "fmt"
)

func printChannel(ch chan int) {
        fmt.Println(<-ch + <-ch)
}

func main() {
        ch := make(chan int)
        go printChannel(ch)
        ch <- 2
        ch <- 3
        fmt.Println("Done")
}




Post a Comment

2 Comments

  1. This is terrible a lot of these are non deterministic and return different values everytime. Terrible

    ReplyDelete