Go Interview Questions

Go Interview Questions



Question
What are some characteristics of the Go programming language?

  * Strong and static typing - the type of the variables can't be changed over time and they have to be defined at compile time
  * Simplicity 
  * Fast compile times
  * Built-in concurrency
  * Garbage collected
  * Platform independent
  * Compile to standalone binary - anything you need to run your app will be compiled into one binary. Very useful for version management in run-time. 

Go also has good community.
                    

Question
What is the difference between var x int = 2 and x := 2?

The result is the same, a variable with the value 2.
With var x int = 2 we are setting the variable type to integer while with x := 2 we are letting Go figure out by itself the type.
                    

Question
True or False? In Go we can redeclare variables and once declared we must use it.

False. We can't redeclare variables but yes, we must used declared variables.
                    

Question
What libraries of Go have you used?

This should be answered based on your usage but some examples are:

  * fmt - formatted I/O
                    

Question
What is the problem with the following block of code? How to fix it? ``` func main() { var x float32 = 13.5 var y int y = x } ```
                    

Question
The following block of code tries to convert the integer 101 to a string but instead we get "e". Why is that? How to fix it? ``` package main import "fmt" func main() { var x int = 101 var y string y = string(x) fmt.Println(y) } ```

It looks what unicode value is set at 101 and uses it for converting the integer to a string.
If you want to get "101" you should use the package "strconv" and replace y = string(x) with y = strconv.Itoa(x)
                    

Question
What is wrong with the following code?: ``` package main func main() { var x = 2 var y = 3 const someConst = x + y } ```
                    

Question
What will be the output of the following block of code?: ``` package main import "fmt" const ( x = iota y = iota ) const z = iota func main() { fmt.Printf("%v\n", x) fmt.Printf("%v\n", y) fmt.Printf("%v\n", z) } ```
                    

Question
What _ is used for in Go?
                    

Question
What will be the output of the following block of code?: ``` package main import "fmt" const ( _ = iota + 3 x ) func main() { fmt.Printf("%v\n", x) } ```