MCQs on Introduction to Go | Go

Discover the essentials of Go (Golang) programming language, from its history and key features to setting up the development environment. Learn how to write and run your first Go program efficiently.


History and Features of Go

  1. Who developed the Go programming language?
    a) James Gosling
    b) Bjarne Stroustrup
    c) Ken Thompson, Rob Pike, and Robert Griesemer
    d) Dennis Ritchie
  2. When was Go first released to the public?
    a) 2005
    b) 2007
    c) 2009
    d) 2010
  3. Which of the following is NOT a feature of the Go programming language?
    a) Static typing
    b) Automatic memory management
    c) Object-oriented programming
    d) Built-in garbage collection
  4. Which company was responsible for the development of Go?
    a) Apple
    b) Microsoft
    c) Google
    d) IBM
  5. Go is often praised for its simplicity. Which of these features contributes to its simplicity?
    a) Complex inheritance structure
    b) Minimalistic syntax and structure
    c) Comprehensive built-in libraries
    d) Multi-threading model
  6. What type of programming model does Go promote?
    a) Object-oriented programming
    b) Functional programming
    c) Concurrent programming
    d) Event-driven programming
  7. Which of these is a key design goal for Go?
    a) Support for complex frameworks
    b) High performance and scalability
    c) Large codebases
    d) Compatibility with legacy systems
  8. In Go, which feature helps achieve better concurrency?
    a) Threads
    b) Goroutines
    c) Processes
    d) Classes
  9. What is one of the main advantages of Go’s garbage collection system?
    a) It runs in the background without user input
    b) It manages memory allocation across multiple cores
    c) It uses a reference counting system
    d) It automatically defragments memory
  10. Which statement is true about Go’s error handling?
    a) Go uses exceptions for error handling
    b) Go uses multiple return values, one of which is an error
    c) Go ignores errors unless explicitly mentioned
    d) Go handles errors using a special error object

Setting up Go Environment (Installation, GOPATH, Modules)

  1. Which of the following is the first step to setting up a Go environment?
    a) Install the Go runtime
    b) Set the GOPATH
    c) Download the Go source code
    d) Install Go modules
  2. What is the default GOPATH directory in Go?
    a) /usr/local/go
    b) $HOME/go
    c) /opt/go
    d) $GOPATH/src
  3. How can you install Go on a Windows machine?
    a) By using the Windows Store
    b) By downloading the Go installer from the official site
    c) By compiling Go from source
    d) By using Homebrew
  4. Which command in Go is used to download dependencies as modules?
    a) go fetch
    b) go mod
    c) go get
    d) go install
  5. What is the purpose of the GOPATH in Go?
    a) To manage the workspace for Go code
    b) To store Go executable binaries
    c) To compile Go programs
    d) To store Go modules
  6. What does the go mod init command do?
    a) Initializes a new Go module in the current directory
    b) Downloads external dependencies for a project
    c) Compiles Go source files
    d) Sets up the GOPATH environment variable
  7. Which of these is true about Go modules?
    a) They allow the use of versioned dependencies
    b) They are used only for Go 1.13+ versions
    c) They are similar to Python packages
    d) They are required for every Go project
  8. How can you check if Go is properly installed on your machine?
    a) Use go -v
    b) Use go check
    c) Use go status
    d) Use go install
  9. What does the go run command do?
    a) Compiles and runs a Go program
    b) Installs a Go package
    c) Executes a Go module
    d) Runs a Go test suite
  10. What is the recommended directory for Go source code?
    a) $GOPATH/src
    b) $HOME/go/src
    c) /usr/src/go
    d) /opt/go/src

Writing and Running Your First Go Program

  1. What is the first line of a Go program?
    a) package main
    b) import "fmt"
    c) func main()
    d) var main()
  2. What function is used as the entry point of a Go program?
    a) main()
    b) start()
    c) run()
    d) init()
  3. Which of these is the correct way to print “Hello, World!” in Go?
    a) fmt.Println("Hello, World!")
    b) println("Hello, World!")
    c) Print("Hello, World!")
    d) System.out.println("Hello, World!")
  4. What does the go run command do?
    a) Compiles and runs a Go source file
    b) Installs dependencies for the program
    c) Sets up Go modules
    d) Starts a Go web server
  5. What should be the first statement of every Go program?
    a) import
    b) func main()
    c) package main
    d) var main()
  6. In Go, how do you declare a variable?
    a) var x int
    b) int x
    c) let x = 0
    d) x = 0
  7. How do you declare and initialize a constant in Go?
    a) const PI = 3.14
    b) var PI = 3.14
    c) let PI = 3.14
    d) def PI = 3.14
  8. What is the file extension for a Go source file?
    a) .go
    b) .gop
    c) .gof
    d) .gol
  9. How do you execute a Go program after writing the code?
    a) go run <filename>
    b) go start <filename>
    c) go execute <filename>
    d) go compile <filename>
  10. What is the command to compile a Go program without running it?
    a) go build
    b) go compile
    c) go create
    d) go make

Answer Key

QNoAnswer (Option with text)
1c) Ken Thompson, Rob Pike, and Robert Griesemer
2c) 2009
3c) Object-oriented programming
4c) Google
5b) Minimalistic syntax and structure
6c) Concurrent programming
7b) High performance and scalability
8b) Goroutines
9a) It runs in the background without user input
10b) Go uses multiple return values, one of which is an error
11a) Install the Go runtime
12b) $HOME/go
13b) By downloading the Go installer from the official site
14c) go get
15a) To manage the workspace for Go code
16a) Initializes a new Go module in the current directory
17a) They allow the use of versioned dependencies
18a) Use go -v
19a) Compiles and runs a Go program
20a) $GOPATH/src
21a) package main
22a) main()
23a) fmt.Println("Hello, World!")
24a) Compiles and runs a Go source file
25c) package main
26a) var x int
27a) const PI = 3.14
28a) .go
29a) go run <filename>
30a) go build

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top