Javatpoint Logo

91-9990449935

 0120-4256464

Go Interview Questions

A list of top frequently asked Go Programming interview questions and answers are given below.


1) What is Go programming language?

GO is an open source programming language developed at Google. It is also known as Golang. This language is designed primarily for system programming.


2) Why should one use Go programming language?

Because Go is an open source programming language so, it is very easy to build simple, reliable and efficient software.


3) Who is known as the father of Go programming language?

Go programming language is designed by Robert Griesemer, Rob Pike, and Ken Thompson. It is developed at Google Inc. in 2009.


4) What are packages in Go program?

Go programs are made up of packages. The program starts running in package main. This program is using the packages with import paths "fmt" and "math/rand".


5) What is a string literal in Go programming?

A string literals specifies a string constant that is obtained from concatenating a sequence of characters.

There are two types of string literals:

  • Raw string literals: The value of raw string literals are character sequence between back quotes ". Its value is specified as a string literal that composed of the uninterrupted character between quotes.
  • Interpreted string literals: It is shown between double quotes " ". The value of the literal is specified as text between the double quotes which may not contain newlines.

6) What is workspace in Go?

A workspace contains Go code. A workspace is a directory hierarchy with three directories at its root.

  • "src" directory contains GO source files organized into packages.
  • "pkg" directory contains package objects.
  • "bin" directory contains executable commands

7) What is the default value of type bool in Go programming?

"false" is the default value of type "bool".


8) What is GOPATH environment variable in go programming?

The GOPATH environment variable specifies the location of the workspace. You must have to set this environment variable while developing Go code.


9) What are the advantages/ benefits of Go programming language?

Advantages/ Benefits of Go programming language:

  • Go is fast and compiles very quickly.
  • It supports concurrency at the language level.
  • It has Garbage collection.
  • It supports various safety features and CSP-style concurrent programming features.
  • Strings and Maps are built into the language.
  • Functions are first class objects in this language.

10) What are the several built-in supports in Go?

A list of built-in supports in Go:

  • Container: container/list,container/heap
  • Web Server: net/http
  • Cryptography: Crypto/md5 ,crypto/sha1
  • Compression: compress/ gzip
  • Database: database/sql

11) What is goroutine in Go programming language?

A goroutine is a function which usually runs concurrently with other functions. If you want to stop goroutine, you pass a signal channel to the goroutine, that signal channel pushes a value into when you want the goroutine to stop.

The goroutine polls that channel regularly as soon as it detects a signal, it quits.


12) How to write multiple strings in Go programming?

To write multiple strings in Go, you should use a raw string literal, where the string is delimited by back quotes.

For example:


13) Is it true that short variable declaration := can be used only inside a function?

Yes. A short variable declaration := can be used only inside a function.


14) How a pointer is represented in Go?

In Go, a pointer is represented by using the *(asterisk) character followed by the type of the stored value.


15) How can you format a string without printing?

You should the following command to format a string without printing:

return fmt.Sprintf ("at %v, %s" , e.When , e.What )


16) What will be the output of the following code?

Ans:

777

17) What is Go Interfaces?

In GO, interfaces is a way to identify the behavior of an object. An interface is created by using the "type" word, followed by a name and the keyword interface. An interface is specified as two things.

  • A set of methods.
  • Also it is referred as type.

18) What is Type assertion in Go? What does it do?

A type assertion takes an interface value and retrieves from it a value of the specified explicit type.

Type conversion is used to convert dissimilar types in GO.


19) How can you check a variable type at runtime in Go programming language?

In Go programming language, there is a special type of switch dedicated to check variable type at runtime. This switch is referred as type switch.


20) Is it recommended to use Global Variables in a program that implements go routines?

Global variables are not recommended because they may get accessed by multiple go routines (threads) concurrently and this can easily lead to an unexpected behavior causing arbitrary results.