Loading, please wait...

A to Z Full Forms and Acronyms

Top 10 GoLang Interview Questions

Jun 24, 2021 Golang, 3669 Views
Top 10 GoLang Interview Questions

Top 10 GoLang Interview Questions

Q1. Explain what is string literals?

A string literals represents a string constant obtained from concatenating a sequence of characters.

There are two forms,

  • Raw string literals: The value of raw string literals are character sequence between back quotes ‘‘.  The value of a string literal is the string composed of the uninterrupted character between quotes.
  • Interpreted string literals: It is represented between double quotes ““. The text between the double quotes which may not contain newlines, forms the value of the literal.

Q2. What data types does Golang use?

Golang uses the following types:

  • Method
  • Boolean
  • Numeric
  • String
  • Array
  • Slice
  • Struct
  • Pointer
  • Function
  • Interface
  • Map
  • Channel

Q3. What are Goroutines?

Goroutines are functions or methods that run concurrently with other functions or methods. Goroutines can be thought of as light weight threads. The cost of creating a Goroutine is tiny when compared to a thread. Its common for Go applications to have thousands of Goroutines running concurrently.

Q4. What is dynamic type declaration of a variable in Go?

A dynamic type variable declaration requires compiler to interpret the type of variable based on value passed to it. Compiler don't need a variable to have type statically as a necessary requirement.

Q5.Explain workspace in GO?

Inside a workspace GO code must be kept.  A workspace is a directory hierarchy with three directories at its root.

  • src contains GO source files organized into packages
  • pkg contains package objects and
  • bin contains executable commands

Q6. What are Lvalue and Rvalue in Golang?

Lvalue

  • Refers to a memory location

  • Represents a variable identifier

  • Mutable

  • May appear on the left or right side of the = operator

Rvalue

  • Represents a data value stored in memory

  • Represents a constant value

  • Always appears on the = operator’s right side.

Q7. What are the advantages of GO?

  • GO compiles very quickly
  • Go supports concurrency at the language level
  • Functions are first class objects in GO
  • GO has garbage collection
  • Strings and Maps are built into the language

Q8.  Explain how pointer is represented in GO?

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

Q9. Explain what Type assertion is used for and how it does it?

Type conversion is used to convert dissimilar types in GO.  A type  assertion takes an interface value and retrieve from it a value of the specified explicit type.

Q10. What are the looping constructs in Go?

Go has only one looping construct: the for loop. The for loop has 3 components separated by semicolons:

  • The Init statement, which is executed before the loop begins. It’s often a variable declaration only visible within the scope of the for loop.

  • The condition expression, which is evaluated as a Boolean before each iteration to determine if the loop should continue.

  • The post statement, which is executed at the end of each iteration.

A to Z Full Forms and Acronyms