Answer these 30+ Go (Programming Language) MCQs and see how sharp is your knowledge of Go (Programming Language).
Scroll down and let's start!
A. They should share the same signatures, including parameter types and return types.
B. They should share the same parameter types but can return different types.
C. All functions should be the same type.
D. The functions should not be a first class type.
A. The number of characters
B. The number of bytes
C. It does not accept string types.
D. The number of code points
A. Do { ... } while i < 5
B. For _,c := range
C. For i := 1; i < 5; i++ { ... }
D. For i < 5 { ... }
A. Values.append(3)
B. Values.insert(3, 3)
C. Append(values, 3)
D. Values = append(values, 3)
A. Const (Write = iota; Read; Execute;)
B. 1
C. 2
D. A random value
A. import "github/gin-gonic/gin"
B. import "https://github.com/gin-gonic/gin"
C. import "../template"
D. import "github.com/gin-gonic/gin"
A. It can be accessed anywhere inside myPackage, not the rest of myModule.
B. It can be accessed by any application that imports myModule.
C. It can be accessed from anywhere in myModule.
D. It can be accessed by other packages in myModule as long as they import myPackage
A. Go test
B. Go test -x
C. Go test --verbose
D. Go test -v
A. All goroutines
B. Any other call to lock that Mutex
C. Any reads or writes of the variable it is locking
D. Any writes to the variable it is locking
A. Pass an int and Mutex to each and count when they return.
B. Loop over a select statement.
C. Sleep for a safe amount of time.
D. Sync.WaitGroup
A. It blocks the other channels.
B. It is meant to be used in select statements without side effects.
C. It blocks the select statement until the time has passed.
D. The goroutine does not end until the time passes.
A. Executing a function concurrently
B. Executing a different case based on the type of a variable
C. Executing a different case based on the value of a variable
D. Executing a different case based on which channel returns first
A. MyVal must be an integer type, such as int, int64, int32, etc.
B. MyVal must be able to be asserted as an int.
C. MyVal must be an interface.
D. MyVal must be a numeric type, such as float64 or int64.
A. A global variable
B. A medium for sending values between goroutines
C. A dynamic array of values
D. A lightweight thread for concurrent programming
A. Check runtime.GOOS.
B. Add a // +build windows comment anywhere in the file.
C. Add a _ prefix to the file name.
D. Add a // +build windows comment at the top of the file.
A. resp, err := http.Post("https://httpbin.org/post", "text/plain", []byte(data))
B. resp, err := http.Post("https://httpbin.org/post", "text/plain", data)
C. resp, err := http.Post("https://httpbin.org/post", "text/plain", strings.NewReader(data))
D. resp, err := http.Post("https://httpbin.org/post", "text/plain", &data)
A. Saveable
B. SaveInterface
C. ISave
D. Saver
A. Does not create; creates
B. Does not create; does not create
C. Creates; creates
D. Creates; does not create
A. The default behavior is case insensitive, but it can be overridden.
B. Fields are matched case sensitive.
C. Fields are matched case insensitive.
D. The default behavior is case sensitive, but it can be overridden.
A. Time.Add() is for performing addition while Time.Sub() is for nesting timestamps.
B. Time.Add() always returns a later time while time.Sub always returns an earlier time.
C. They are opposites. Time.Add(x) is the equivalent of Time.Sub(-x).
D. Time.Add() accepts a Duration parameter and returns a Time while Time.Sub() accepts a Time parameter and returns a Duration.
A. Every field must have all tags to compile.
B. It tightly couples different layers of your application.
C. Any tags after the first are ignored.
D. Missing tags panic at runtime.
A. In the main function
B. Immediately after a line that might panic
C. Inside a deferred function
D. At the beginning of a function that might panic
A. Println(message)
B. log.New(os.Stderr, "", 0).Println(message)
C. fmt.Errorf("%s\n", message)
D. Fmt.Fprintln(os.Stderr, message)
A. Use a proxy.
B. Change the import path.
C. Use a replace directive in go.mod.
D. Use a replace directory.
A. Go test all
B. Go run --all
C. Go test .
D. Go test ./...
A. Any, it accepts arbitary bytes
B. Any Unicode format
C. UTF-8 or ASCII
D. UTF-8
A. There is no difference.
B. T.Fatal does not crash the test harness, preserving output messages.
C. T.Fatal stops execution of the subtest and continues with other test cases.
D. T.Fatal stops all tests and contains extra information about the failed subtest.
A. It raises a panic.
B. It prints the log and then raises a panic.
C. It prints the log and then safely exits the program.
D. It exits the program.
A. "2006-01-02"
B. "YYYY-mm-dd"
C. "y-mo-d"
D. "year-month-day"
A. Log.Error(err)
B. log.Printf("error: %v", err)
C. log.Printf(log.ERROR, err)
D. log.Print("error: %v", err)
A. Any that starts with test
B. Any files that include the word test
C. Only files in the root directory that end in _test.go
D. Any that ends in _test.go
A. Have a cmd directory and a directory per executable inside it.
B. Comment out main.
C. Use build tags.
D. Have a pkg directory and a directory per executable inside it.
A. Set GOOS to arm64 and GOARCH to darwin.
B. Set GOOS to osx and GOARCH to arm64.
C. Set GOOS to arm64 and GOARCH to osx.
D. Set GOOS to darwin and GOARCH to arm64.
A. go(fmt.Println("Hello Gopher!"))
B. go func() { fmt.Println("Hello Gopher!") }
C. go fmt.Println("Hello Gopher!")
D. Go fmt.Println("Hello Gopher!")
A. In pseudo-random order that cannot be predicted
B. In reverse order of how they were added, last in first out
C. Sorted by key in ascending order
D. In the order they were added, first in first out
A. There is no customizing the string representation of a type.
B. Build it in pieces each time by calling individual fields.
C. Implement a method String() string
D. Create a wrapper function that accepts your type and outputs a string.