Question 1. What Are The Benefits Of Using Go Programming?
Answer :
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
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
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
ReplyDeleteI suggest adding something similar that requires programming.
Thanks for your suggest homyse, I can do that asap.
ReplyDelete