MCQ Related “GoLang”

  1. What does Go primarily focus on?
    • A) Object-oriented programming
    • B) Concurrent programming
    • C) Functional programming
    • D) Scripting
  2. Which of the following is a correct way to declare a variable in Go?
    • A) var x int
    • B) int x
    • C) x int
    • D) var int x
  3. What is the keyword for defining a constant in Go?
    • A) constant
    • B) const
    • C) define
    • D) let
  4. Which function is the entry point of a Go program?
    • A) Start()
    • B) main()
    • C) run()
    • D) init()
  5. What is the built-in package to handle input and output in Go?
    • A) fmt
    • B) io
    • C) output
    • D) input
  6. How can you create a slice in Go?
    • A) slice := make([]int, 0)
    • B) slice := []int{}
    • C) Both A and B
    • D) slice int[]
  7. Go uses which type of garbage collection method?
    • A) Reference counting
    • B) Mark and sweep
    • C) Generational
    • D) None of the above
  8. What is a goroutine?
    • A) A type of module
    • B) A lightweight thread
    • C) A standard library
    • D) A package manager
  9. Which keyword is used for creating a pointer in Go?
    • A) ref
    • B) ptr
    • C) &
    • D) *
  10. How do you handle errors in Go?
    • A) Using exceptions
    • B) Using the error type
    • C) Using return codes
    • D) All of the above
  11. What is the purpose of the defer statement?
    • A) To declare variables
    • B) To schedule a function call
    • C) To return multiple values
    • D) To create a loop
  12. In Go, how is a map declared?
    • A) var m map[string]int
    • B) m := map[string]int{}
    • C) Both A and B
    • D) map m[string]int
  13. What is a struct in Go?
    • A) A built-in function
    • B) A user-defined type
    • C) A standard module
    • D) A package type
  14. Which keyword is used to create an interface?
    • A) interface
    • B) type
    • C) struct
    • D) package
  15. What is the Go keyword for a regular function declaration?
    • A) func
    • B) define
    • C) method
    • D) function
  16. How do you import a package in Go?
    • A) import “package-name”
    • B) include “package-name”
    • C) load “package-name”
    • D) require “package-name”
  17. What does the range keyword do in a for loop?
    • A) Iterates over maps and slices
    • B) Creates a loop variable
    • C) Breaks out of a loop
    • D) Both A and B
  18. What is the syntax to create a channel in Go?
    • A) ch := make(chan int)
    • B) ch : int
    • C) channel ch int
    • D) ch := channel int{}
  19. Which function is used to convert a string to an integer in Go?
    • A) strconv.ParseInt
    • B) stringToInt
    • C) convert.Int
    • D) numify
  20. How do you define a method on a struct in Go?
    • A) func (s MyStruct) MethodName() {}
    • B) method (s MyStruct) {}
    • C) func MethodName(s MyStruct) {}
    • D) struct MethodName(s MyStruct) {}
  21. Which keyword is used to define a type alias in Go?
    • A) type
    • B) alias
    • C) typedef
    • D) newtype
  22. Can Go interfaces have methods with implementations?
    • A) Yes
    • B) No
    • C) Only in versions greater than 1.10
    • D) Only for built-in types
  23. What do goroutines communicate through?
    • A) Memory pointers
    • B) Channels
    • C) Mutexes
    • D) Interfaces
  24. Which of the following is a keyword for declaring a constant?
    • A) const
    • B) fixed
    • C) static
    • D) immutable
  25. How do you concatenate strings in Go?
    • A) + operator
    • B) concat() function
    • C) merge() function
    • D) Both A and B
  26. What do you use to execute a goroutine?
    • A) start()
    • B) go
    • C) thread()
    • D) execute()
  27. How do you create a new package in Go?
    • A) Create a new folder with “package-name”
    • B) Using the package keyword in a file
    • C) Both A and B
    • D) By importing it from another repo
  28. How does Go handle multiple return values?
    • A) It doesn’t support them
    • B) Through tuples
    • C) By passing references
    • D) By specifying return types
  29. What is the Go approach to dealing with concurrency?
    • A) Threads
    • B) Event-driven
    • C) Goroutines and channels
    • D) Callbacks
  30. How do you implement concurrency in Go?
    • A) Using threads
    • B) Using subprocesses
    • C) Using goroutines
    • D) Using async functions
  31. Which of the following is NOT a built-in data type in Go?
    • A) int
    • B) bool
    • C) string
    • D) float64
  32. How are command line arguments accessed in Go?
    • A) os.args
    • B) os.Args
    • C) arguments
    • D) cmdline
  33. What is the keyword for defining a new struct type?
    • A) new
    • B) struct
    • C) create
    • D) type
  34. Which package should you use for regular expression operations in Go?
    • A) regex
    • B) re
    • C) regexp
    • D) expressions
  35. What is a buffer in Go?
    • A) A fixed memory allocation
    • B) A type of variable
    • C) A channel with capacity
    • D) None of the above
  36. How do you close a channel in Go?
    • A) close(ch)
    • B) ch.close()
    • C) ch.close()
    • D) Both A and B
  37. Which function can you use to read from files in Go?
    • A) readFile()
    • B) ioutil.ReadFile
    • C) os.Read
    • D) file.Read()
  38. How can you define a data structure that can contain different types of data in Go?
    • A) Using interface{}
    • B) Using var
    • C) Using a slice
    • D) Using a map
  39. What is the zero value of a pointer in Go?
    • A) nil
    • B) 0
    • C) false
    • D) “”
  40. How do you start a new Go module?
    • A) go start
    • B) go module init
    • C) go mod init
    • D) module init
  41. Which of the following is used to handle JSON in Go?
    • A) encoding/json
    • B) json/encode
    • C) json.go
    • D) jsonify
  42. What is the output of fmt.Println(3 == 3.0) in Go?
    • A) true
    • B) false
    • C) error
    • D) nil
  43. Which Go keyword is used to define an anonymous function?
    • A) func
    • B) anonymous
    • C) lambda
    • D) closure
  44. What is the Go equivalent of a constructor?
    • A) New()
    • B) func typeName() {}
    • C) init()
    • D) None of the above
  45. What is the default package used for testing in Go?
    • A) testing
    • B) test
    • C) assert
    • D) mock
  46. How can you implement a custom error in Go?
    • A) By defining a new type that implements the Error interface
    • B) Using the errors package
    • C) Both A and B
    • D) By using panic()
  47. Which statement is true about Go’s concurrency model?
    • A) It uses multi-threading
    • B) It uses shared memory
    • C) It promotes communication over shared memory
    • D) It does not support concurrency
  48. What is a race condition?
    • A) When multiple processes run simultaneously
    • B) When two or more goroutines access shared resources concurrently
    • C) A type of deadlock
    • D) None of the above
  49. How do you log messages in Go?
    • A) log.Print()
    • B) log.Log()
    • C) print()
    • D) write()
  50. What does the panic function do in Go?
    • A) It stops execution and begins to unwind the stack
    • B) It prints an error message
    • C) It terminates the program