Go Coding MCQ Questions and Answers

Welcome to Golang Programming Coding MCQ Questions. Here, we present 20 MCQs (Multiple-Choice Questions) with code snippets to test your understanding of Golang programming coding and logical stills. Let's get started!

1. What will be the output of the following Go program?

package main
import "fmt"
func main() {
    fmt.Println(10 + 5 + "Hello")
}
a) type mismatch error
b) 15Hello
c) Hello15
d) Compilation error

2. What does this Go code snippet output?

package main
import "fmt"
func main() {
    x := 8
    y := 3
    fmt.Println(x % y)
}
a) 2
b) 2.67
c) 3
d) None of the above

3. Consider the following Go code. What will it print?

package main
import "fmt"
func main() {
    var x = 10
    change(&x)
    fmt.Println(x)
}
func change(x *int) {
    *x = 20
}
a) 10
b) 20
c) 0
d) nil

4. What is the output of the following Go function?

package main
import "fmt"
func main() {
    s1 := "hello"
    s2 := "hello"
    fmt.Println(s1 == s2)
}
a) True
b) False
c) Error
d) Nil

5. What will this Go program output?

package main
import "fmt"
func main() {
    fmt.Println("5" + "2" + "3")
}
a) 10
b) 5
c) 523
d) 53

6. Analyze the following Go code snippet. What is its output?

package main
import "fmt"
func main() {
    fmt.Println(10.5, 10.0)
}
a) 10.5 10.0
b) 10 10
c) Error
d) None of the above

7. Consider the following Go code. What will it print?

package main
import "fmt"
func main() {
    i := 0
    fmt.Println(i++)
}
a) 0
b) 1
c) Compilation error
d) Runtime error

8. What does this Go code output?

package main
import "fmt"
func main() {
    x := 5
    fmt.Println(x > 3 ? "Yes" : "No")
}
a) Yes
b) No
c) 3
d) Compilation error

9. What will the following Go code print?

package main
import "fmt"
func main() {
numbers := []int{1, 2, 3}
fmt.Println(len(numbers))
}
a) 3
b) 4
c) 2
d) Compilation error

10. What does the following Go program output?

package main
import "fmt"
func main() {
    x := 5
    y := 10
    x, y = y, x
    fmt.Println(x, y)
}
a) 5 10
b) 10 5
c) 10 10
d) None of the above

11. Analyze the following Go code snippet. What will it output?

package main
import "fmt"
func main() {
s := []string{"a", "b", "c"}
for _, v := range s {
    go fmt.Print(v)
}
}
a) abc
b) cba
c) Random order each run
d) Nothing

12. What will the following Go code output?

package main
import "fmt"
func main() {
    defer fmt.Println("world")
    fmt.Println("hello")
}
a) hello
b) world
c) hello world
d) world hello

13. Consider the following Go code. What will it print?

package main
import "fmt"
func main() {
    fmt.Println([]byte("Hello"))
}
a) [72 101 108 108 111]
b) Hello
c) [H e l l o]
d) Compilation error

14. What is the output of the following Go function?

package main
import "fmt"
func main() {
    var x interface{} = "Hello"
    switch v := x.(type) {
        case string:
        fmt.Println(v)
        default:
        fmt.Println("Unknown")
    }
}
a) Hello
b) Unknown
c) Compilation error
d) Runtime error

15. What will this Go program output?

package main
import "fmt"
func main() {
    fmt.Println("10" > "2")
}
a) true
b) false
c) Compilation error
d) Runtime error

16. What does the following Go code snippet output?

package main
import "fmt"
func main() {
    var a = 1.9999
    var b = int(a)
    fmt.Println(b)
}
a) 1
b) 2
c) Error
d) None of the above

17. Consider the following Go code. What will it print?

package main
import "fmt"
func main() {
a := [3]int{1, 2, 3}
b := a
b[1] = 5
fmt.Println(a[1])
}
a) 1
b) 2
c) 5
d) Compilation error

18. What does the following Go code output?

package main
import "fmt"
func main() {
m := map[string]int{"Alice": 23, "Bob": 25}
v, ok := m["Charlie"]
fmt.Println(v, ok)
}
a) 0 false
b) 0 true
c) nil false
d) None of the above

19. What will the following Go code print?

package main
import "fmt"
func main() {
    s := make([]string, 0)
    s = append(s, "a", "b")
    fmt.Println(len(s), cap(s))
}
a) 2 2
b) 2 3
c) 0 2
d) 1 2

20. What does this code snippet output?

package main
import "fmt"
func main() {
    fmt.Println('A' + '1')
}
a) A1
b) 146
c) Error
d) None of the above

Comments