Golang interview questions – Part 1

– Explain what is GO?
GO is an open-source programming language that makes it easy to build simple, reliable and efficient software. Programs are constructed from packages, whose properties allow efficient management of dependencies.

– What is syntax like in GO?
Syntax in GO is specified using Extended Backus-Naur Form (EBNF)
Production = production_name “=” [ Expression ]
Expression = Alternative { “l” Alternative }
Alternative = Term { Term }
Term = Production_name l token [ “…”token] l Group l Option l Repetition
Group = “ ( “ Expression”)”
Option = “ [ “ Expression “ ]”
Repetition = “ {“ Expression “}”

– Explain what is string literals?
A string literal 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 the 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.

-Explain packages in Go program?
Every GO program is made up of packages. The program starts running in package main. This
program is using the packages with import paths “fmt” and “math/rand”.

– 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

– Explain how to use custom packages in GO language?
If you are making your library a separate go gettable project and if your library is for internal use then you can code like this Under the directory of your project place, the directory with library files Refer to the library using its path relative to the root of your workspace consisting the project
For example,

Now, in main.go you could import myprojec/mylib.

– Explain what is GOPATH environment variable?
The GOPATH environment variable determines the location of the workspace. It is the only environment variable that you have to set when developing Go code.

– Explain how you can do testing in GO?
It has a lightweight testing framework consists of the go test command and the testing package.
To write a test you have to create a file with a name ending in _testing. Go which contains functions
named TestXXX with signature func (t *testing.T). The test framework runs each such function.

– Explain what is string types?
A string type represents the set of string values, and string values are a sequence of bytes. Strings
once created is not possible to change.

– 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

– List out the built-in support in GO?
The available built-in-support in GO includes
Container: container/list , container/heap
Web Server: net/http
Cryptography: Crypto/md5 , crypto/sha1
Compression: compress/ gzip
Database: database/sql

– Explain what is goroutine in GO? How you can stop goroutine?
A goroutine is a function which is capable of running concurrently with other functions
To stop goroutine, you pass the goroutine a signal channel, that signal channel is used to push 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.

– Explain how you can write multiline strings in GO?
To write the multiline string in GO you can use a raw string literal, where the string is delimited by back
quotes rather than double-quotes.
‘ line 1
line 2
line 3 ’

– Explain how you access command-line arguments passed to a GO program?
You can access the command line argument using the os.Args variables. For example,
Package main

– Explain how the pointer is represented in GO?
In GO a pointer is represented by using the * (asterisk) character followed by the type of the stored

– How you can format a string without printing?
To format a string without printing you have to use command
return fmt.Sprintf ( “at %v, %s” , e.When , e.What )

– Explain how arrays in GO works differently than C?
In GO Array works differently than it works in C
Arrays are values, assigning one array to another copy all the elements
If you pass an array to a function, it will receive a copy of the array, not a pointer to it
The size of an array is part of its type. The types [10] int and [20] int are distinct

– Explain GO Interfaces?
In GO, interfaces are a way to specify 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 to as type

– Explain what type of 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 retrieves from it a value of the specified explicit type.

– In GO language how you can check the variable type at runtime?
A special type of switch is dedicated to GO to check the variable type at runtime, this switch is referred to as type switch. Also, you can switch on the type of an interface value with Type Switch

Shariful Islam Nayon

Shariful Islam | Full Stack Python/Django Developer I am Linux lover self motivated software craftsman open source contributor.My interested area Data Structure,Algorithm,Big data,Machine learning Dhaka, Bangladesh http://nayon.net/

Leave a Reply

Your email address will not be published. Required fields are marked *