Go Aptitude Test - MCQ Questions with Answers

This Go Aptitude Test provides 25 multiple-choice questions for beginners to test Go (Golang) programming basic concepts and syntax.

1. What is the correct way to declare a variable in Go?

a) var x int
b) int x
c) x := int
d) declare x int

2. How do you create a new slice in Go?

a) slice := []int{}
b) slice := make([]int)
c) []int slice = new[]
d) make slice[]int

3. Which keyword is used to define a function in Go?

a) func
b) function
c) def
d) Func

4. What is the default zero value of a pointer in Go?

a) 0
b) nil
c) NaN
d) undefined

5. What does the append function do?

a) Concatenates two strings
b) Appends items to the end of a slice
c) Increases the size of an array
d) None of the above

6. How do you specify that a variable is of an interface type in Go?

a) var x interface{}
b) var x = interface{}
c) x := interface{}
d) interface x {}

7. Which of these data types does not exist in Go?

a) slice
b) tuple
c) map
d) array

8. What is the output of len("GoLang")?

a) 5
b) 6
c) 7
d) Error

9. Which keyword is used for a loop that does not specify the iteration count?

a) for
b) while
c) loop
d) foreach

10. How are maps created in Go?

a) map := new(map)
b) map := make(map[string]int)
c) make(map[string]int)
d) new map[string]int

11. What does the range keyword do in Go?

a) Sets a range of numbers
b) Iterates over elements in a variety of data structures
c) Specifies array indices
d) Defines a new range type

12. What is the default value of an int in Go?

a) 1
b) 0
c) -1
d) nil

13. How do you specify a multi-line comment in Go?

a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <!-- This is a comment -->

14. Which of these is the correct way to declare a constant in Go?

a) const x int = 10
b) x := const 10
c) const x = 10
d) constant x = 10

15. How is concurrency handled in Go?

a) threads
b) callbacks
c) goroutines
d) promises

16. What is the use of the select statement in Go?

a) To select specific cases to run in a switch
b) To perform SQL-like queries in Go
c) To wait on multiple channel operations
d) To choose between different variable types

17. Which package must be imported to use the Println function?

a) os
b) sys
c) main
d) fmt

18. What is the type of keyword used to define a new struct in Go?

a) struct
b) type
c) new
d) define

19. How do you create a new error in Go?

a) errors.New("error message")
b) new Error("error message")
c) make(Error, "error message")
d) throw new Error("error message")

20. What does the defer keyword do?

a) Delays the execution of a function until the surrounding function returns
b) Defers the declaration of a variable
c) Prevents a function from executing
d) Runs a function in a defer loop

21. How do you declare a package in Go?

a) package main
b) package = "main"
c) new package("main")
d) create package main

22. What is the correct way to handle errors in Go?

a) try...catch
b) if err != nil { ... }
c) on error
d) catch(err)

23. How do you import multiple packages in Go?

a) import "fmt", "os"
b) import ("fmt" "os")
c) import ("fmt"; "os")
d) import ("fmt", "os")

24. What is the built-in interface in Go that has zero methods?

a) Stringer
b) Reader
c) Empty
d) Any

25. Which method can convert an integer to a string in Go?

a) int.toString()
b) strconv.Itoa(int)
c) string(int)
d) fmt.Sprint(int)