- What does Go primarily focus on?
- A) Object-oriented programming
- B) Concurrent programming
- C) Functional programming
- D) Scripting
- 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
- What is the keyword for defining a constant in Go?
- A) constant
- B) const
- C) define
- D) let
- Which function is the entry point of a Go program?
- A) Start()
- B) main()
- C) run()
- D) init()
- What is the built-in package to handle input and output in Go?
- A) fmt
- B) io
- C) output
- D) input
- How can you create a slice in Go?
- A) slice := make([]int, 0)
- B) slice := []int{}
- C) Both A and B
- D) slice int[]
- Go uses which type of garbage collection method?
- A) Reference counting
- B) Mark and sweep
- C) Generational
- D) None of the above
- What is a goroutine?
- A) A type of module
- B) A lightweight thread
- C) A standard library
- D) A package manager
- Which keyword is used for creating a pointer in Go?
- A) ref
- B) ptr
- C) &
- D) *
- How do you handle errors in Go?
- A) Using exceptions
- B) Using the error type
- C) Using return codes
- D) All of the above
- What is the purpose of the
deferstatement?- A) To declare variables
- B) To schedule a function call
- C) To return multiple values
- D) To create a loop
- 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
- What is a struct in Go?
- A) A built-in function
- B) A user-defined type
- C) A standard module
- D) A package type
- Which keyword is used to create an interface?
- A) interface
- B) type
- C) struct
- D) package
- What is the Go keyword for a regular function declaration?
- A) func
- B) define
- C) method
- D) function
- How do you import a package in Go?
- A) import “package-name”
- B) include “package-name”
- C) load “package-name”
- D) require “package-name”
- What does the
rangekeyword 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
- 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{}
- Which function is used to convert a string to an integer in Go?
- A) strconv.ParseInt
- B) stringToInt
- C) convert.Int
- D) numify
- 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) {}
- Which keyword is used to define a type alias in Go?
- A) type
- B) alias
- C) typedef
- D) newtype
- 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
- What do goroutines communicate through?
- A) Memory pointers
- B) Channels
- C) Mutexes
- D) Interfaces
- Which of the following is a keyword for declaring a constant?
- A) const
- B) fixed
- C) static
- D) immutable
- How do you concatenate strings in Go?
- A) + operator
- B) concat() function
- C) merge() function
- D) Both A and B
- What do you use to execute a goroutine?
- A) start()
- B) go
- C) thread()
- D) execute()
- 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
- 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
- What is the Go approach to dealing with concurrency?
- A) Threads
- B) Event-driven
- C) Goroutines and channels
- D) Callbacks
- How do you implement concurrency in Go?
- A) Using threads
- B) Using subprocesses
- C) Using goroutines
- D) Using async functions
- Which of the following is NOT a built-in data type in Go?
- A) int
- B) bool
- C) string
- D) float64
- How are command line arguments accessed in Go?
- A) os.args
- B) os.Args
- C) arguments
- D) cmdline
- What is the keyword for defining a new struct type?
- A) new
- B) struct
- C) create
- D) type
- Which package should you use for regular expression operations in Go?
- A) regex
- B) re
- C) regexp
- D) expressions
- 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
- How do you close a channel in Go?
- A) close(ch)
- B) ch.close()
- C) ch.close()
- D) Both A and B
- Which function can you use to read from files in Go?
- A) readFile()
- B) ioutil.ReadFile
- C) os.Read
- D) file.Read()
- 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
- What is the zero value of a pointer in Go?
- A) nil
- B) 0
- C) false
- D) “”
- How do you start a new Go module?
- A) go start
- B) go module init
- C) go mod init
- D) module init
- Which of the following is used to handle JSON in Go?
- A) encoding/json
- B) json/encode
- C) json.go
- D) jsonify
- What is the output of
fmt.Println(3 == 3.0)in Go?- A) true
- B) false
- C) error
- D) nil
- Which Go keyword is used to define an anonymous function?
- A) func
- B) anonymous
- C) lambda
- D) closure
- What is the Go equivalent of a constructor?
- A) New()
- B) func typeName() {}
- C) init()
- D) None of the above
- What is the default package used for testing in Go?
- A) testing
- B) test
- C) assert
- D) mock
- 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()
- 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
- 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
- How do you log messages in Go?
- A) log.Print()
- B) log.Log()
- C) print()
- D) write()
- What does the
panicfunction do in Go?- A) It stops execution and begins to unwind the stack
- B) It prints an error message
- C) It terminates the program