1. What is the correct syntax for declaring a variable in Go?
Answer:
Explanation:
In Go, a variable is declared using the 'var' keyword followed by the variable name and the type. The syntax is 'var variableName variableType'.
2. Which of the following is used for type inference in Go?
Answer:
Explanation:
The ':=' syntax is used for type inference in Go, where the compiler determines the type of the variable based on the initial value assigned to it.
3. How do you declare a block of variables in Go?
Answer:
Explanation:
In Go, a block of variables is declared using the 'var' keyword followed by parentheses. Each variable declaration is separated by a semicolon.
4. What is the zero value of a string variable in Go?
Answer:
Explanation:
The zero value of a string in Go is an empty string, denoted by "".
5. Can you redeclare a variable in the same scope in Go?
Answer:
Explanation:
In Go, you cannot redeclare a variable in the same scope. Once a variable is declared, its name cannot be reused in the same scope.
6. Which of the following is NOT a valid way to declare and initialize a variable in Go?
Answer:
Explanation:
The correct syntax to declare and initialize a variable in Go does not include the type before the variable name when using the '=' assignment. 'd int = 40' is incorrect.
7. How do you declare a package level variable in Go?
Answer:
Explanation:
Package level variables in Go are declared outside of any function using the 'var' keyword. They are accessible from any function within the package.
8. What is the default value of a boolean variable in Go?
Answer:
Explanation:
The zero value of a boolean in Go is 'false'.
9. Which of the following declares a pointer variable in Go?
Answer:
Explanation:
In Go, a pointer variable is declared using the 'var' keyword, followed by the variable name, a star (*), and the type of the value it points to.
10. How do you initialize a variable with a constant value in Go?
Answer:
Explanation:
In Go, constants are declared using the 'const' keyword. The value of a constant should be known at compile-time and cannot be changed.