Skip to main content

GOLANG INTERVIEW QUESTIONS & ANSWERS

Question 1. What Are The Benefits Of Using Go Programming?

Answer :
  • Support for environment adopting patterns similar to dynamic languages. For example type inference (x := 0 is valid declaration of a variable x of type int).
  • Compilation time is fast.
  • InBuilt concurrency support: light-weight processes (via goroutines), channels, select statement.
  • Conciseness, Simplicity, and Safety.
  • Support for Interfaces and Type embdding.
  • Production of statically linked native binaries without external dependencies.


Question 2. Does Go Support Type Inheritance?
Answer : No support for type inheritance.

Question 3. Does Go Support Operator Overloading?
Answer : No support for operator overloading.

Question 4. Does Go Support Method Overloading?
Answer : No support for method overloading.

Question 5. Does Go Support Pointer Arithmetics?
Answer : No support for pointer arithmetic.

Question 6. Does Go Support Generic Programming?
Answer : No support for generic programming.

Question 7. Is Go A Case Sensitive Language?
Answer : Yes! Go is a case sensitive programming language.


Question 8. What Is An Array?
Answer : Array is collection of similar data items under a common name.

Question 9. What Is A Nil Pointers In Go?
Answer : Go compiler assign a Nil value to a pointer variable in case you do not have exact address to be assigned. This is done at the time of variable declaration. A pointer that is assigned nil is called a nil pointer. The nil pointer is a constant with a value of zero defined in several standard libraries.


Question 10. What Are Maps In Go?
Answer : Go provides another important data type map which maps unique keys to values. A key is an object that you use to retrieve a value at a later date. Given a key and a value, you can strore the value in a Map object. After value is stored, you can retrieve it by using its key.


Question 11. How To Delete An Entry From A Map In Go?
Answer : delete() function is used to delete an entry from the map. It requires map and corresponding key which is to be deleted.

Question 12. What Is Type Casting In Go?
Answer : Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int. You can convert values from one type to another using the cast operator as following:

type_name(expression)

Question 13. What Are Interfaces In Go?
Answer : Go programming provides another data type called interfaces which represents a set of method signatures. struct data type implements these interfaces to have method definitions for the method signature of the interfaces.


Question 14. What Is The Difference Between Len() And Cap() Functions Of Slice In Go?
Answer : len() function returns the elements presents in the slice where cap() function returns the capacity of the slice as how many elements it can be accommodated.

Question 15. How To Get A Sub-slice Of A Slice?
Answer : Slice allows lower-bound and upper bound to be specified to get the subslice of it using[lower-bound:upper-bound].

Question 16. What Is Range In Go?
Answer : The range keyword is used in for loop to iterate over items of an array, slice, channel or map. With array and slices, it returns the index of the item as an integer. With maps, it returns the key of the next key-value pair.


Question 17. What Is Static Type Declaration Of A Variable In Go?
Answer : Static type variable declaration provides assurance to the compiler that there is one variable existing with the given type and name so that compiler proceeds for further compilation without needing complete detail about the variable. A variable declaration has its meaning at the time of compilation only, the compiler needs actual variable declaration at the time of linking of the program.

Question 18. What Is Dynamic Type Declaration Of A Variable In Go?
Answer : A dynamic type variable declaration requires the compiler to interpret the type of the variable based on the value passed to it. Compiler doesn't need a variable to have type statically as a necessary requirement.

Question 19. Can You Declare Multiple Types Of Variables In Single Declaration In Go?
Answer :Yes Variables of different types can be declared in one go using type inference.

var a, b, c = 3, 4, "foo"

Question 20. How To Print Type Of A Variable In Go?
Answer : Following code prints the type of a variable −

var a, b, c = 3, 4, "foo"
fmt.Printf("a is of type %Tn", a)


Question 21. What Is The Purpose Of Break Statement?
Answer : Break terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.

Question 22. What Is The Purpose Of Continue Statement?
Answer : Continue causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

Question 23. What Is The Purpose Of Goto Statement?
Answer : goto transfers control to the labeled statement.

Question 24. Explain The Syntax For 'for' Loop?
Answer : The syntax of a for loop in Go programming language is −

for [condition |  ( init; condition; increment ) | Range]
{
   statement(s);
}

if a range is available, then for loop executes for each item in the range.

Question 18. Explain The Syntax To Create A Function In Go?
Answer : The general form of a function definition in Go programming language is as follows −

func function_name( [parameter list] ) [return_types]
{
   body of the function
}

Question 19. Can You Return Multiple Values From A Function?
Answer : A Go function can return multiple values. For example −

package main
import "fmt"
func swap(x, y string) (string, string) {
   return y, x
}
func main() {
   a, b := swap("Mahesh", "Kumar")
   fmt.Println(a, b)
}

Question 25. In How Many Ways You Can Pass Parameters To A Method?
Answer : While calling a function, there are two ways that arguments can be passed to a function:

Call by value: This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.

Call by reference: This method copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument.

Question 26. What Is The Default Way Of Passing Parameters To A Function?
Answer : By default, Go uses call by value to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function while calling max() function used the same method.

Question 27. What Do You Mean By Function As Value In Go?
Answer : Go programming language provides flexibility to create functions on the fly and use them as values. We can set a variable with a function definition and use it as the parameter to a function.

Question 28. What Are The Function Closures?
Answer : Functions closure are anonymous functions and can be used in dynamic programming.


Question 29. What Is Lvalue And Rvalue?
Answer :The expression appearing on right side of the assignment operator is called as rvalue. Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The lvalue should designate to a variable not a constant.

Question 30. What Is The Difference Between Actual And Formal Parameters?
Answer : The parameters sent to the function at calling end are called as actual parameters while at the receiving of the function definition called as formal parameters.

Question 31. What Is The Difference Between Variable Declaration And Variable Definition?
Answer : Declaration associates type to the variable whereas definition gives the value to the variable.

Question 32. Explain Modular Programming?
Answer : Dividing the program into subprograms (modules/function) to achieve the given task is the modular approach. More generic functions definition gives the ability to re-use the functions, such as built-in library functions.

Question 34. Which Key Word Is Used To Perform Unconditional Branching?
Answer :goto

Comments

  1. Very good, but I'd recommend also adding some practical coding questions. Most interviewers will not just ask theoretical questions like this, but will also test your coding skills with questions like some of these Golang interview questions: https://www.testdome.com/d/golang-interview-questions/589

    I suggest adding something similar that requires programming.

    ReplyDelete
  2. Thanks for your suggest homyse, I can do that asap.

    ReplyDelete

Post a Comment

Popular posts from this blog

Java Loops II print each element of our series as a single line of space-separated values.

We use the integers  ,  , and   to create the following series: You are given   queries in the form of  ,  , and  . For each query, print the series corresponding to the given  ,  , and   values as a single line of   space-separated integers. Input Format The first line contains an integer,  , denoting the number of queries.  Each line   of the   subsequent lines contains three space-separated integers describing the respective  ,  , and   values for that query. Constraints Output Format For each query, print the corresponding series on a new line. Each series must be printed in order as a single line of   space-separated integers. Sample Input 2 0 2 10 5 3 5 Sample Output 2 6 14 30 62 126 254 510 1022 2046 8 14 26 50 98 Explanation We have two queries: We use  ,  , and   to produce some series  : ... and so on. Once we hit  , we print the first ten terms as a single line of space-separate

Java Currency Formatter Solution

Given a  double-precision  number,  , denoting an amount of money, use the  NumberFormat  class'  getCurrencyInstance  method to convert   into the US, Indian, Chinese, and French currency formats. Then print the formatted values as follows: US: formattedPayment India: formattedPayment China: formattedPayment France: formattedPayment where   is   formatted according to the appropriate  Locale 's currency. Note:  India does not have a built-in Locale, so you must  construct one  where the language is  en  (i.e., English). Input Format A single double-precision number denoting  . Constraints Output Format On the first line, print  US: u  where   is   formatted for US currency.  On the second line, print  India: i  where   is   formatted for Indian currency.  On the third line, print  China: c  where   is   formatted for Chinese currency.  On the fourth line, print  France: f , where   is   formatted for French currency. Sample

Java Substring Comparisons

We define the following terms: Lexicographical Order , also known as  alphabetic  or  dictionary  order, orders characters as follows:  For example,  ball < cat ,  dog < dorm ,  Happy < happy ,  Zoo < ball . A  substring  of a string is a contiguous block of characters in the string. For example, the substrings of  abc  are  a ,  b ,  c ,  ab ,  bc , and  abc . Given a string,  , and an integer,  , complete the function so that it finds the lexicographically  smallest  and  largest substrings of length  . Input Format The first line contains a string denoting  . The second line contains an integer denoting  . Constraints  consists of English alphabetic letters only (i.e.,  [a-zA-Z] ). Output Format Return the respective lexicographically smallest and largest substrings as a single newline-separated string. Sample Input 0 welcometojava 3 Sample Output 0 ava wel Explanation 0 S