1. How do you declare an array of 10 integers in Go?
Answer:
Explanation:
In Go, arrays are declared by specifying the type of the elements and the number of elements within square brackets before the variable name.
2. What is the length of the array declared as var myArray [5]int in Go?
Answer:
Explanation:
The length of the array 'myArray' is 5, as defined by the number in the square brackets.
3. How do you access the third element in an array named 'data' in Go?
Answer:
Explanation:
Arrays in Go are zero-indexed, so the third element is accessed with index 2.
4. In Go, are arrays passed by value or by reference to functions?
Answer:
Explanation:
In Go, arrays are passed by value to functions, meaning a copy of the array is passed.
5. What happens if you try to access an index out of bounds in a Go array?
Answer:
Explanation:
Accessing an index out of bounds in a Go array causes a runtime panic.
6. How are uninitialized elements in a Go array set?
Answer:
Explanation:
In Go, uninitialized elements in an array are automatically set to the zero value of the array's type.
7. What is the correct way to initialize an array with specific values in Go?
Answer:
Explanation:
In Go, arrays can be initialized with specific values using curly braces following the type and size.
8. Can you change the size of an array after its declaration in Go?
Answer:
Explanation:
In Go, the size of an array is fixed upon declaration and cannot be changed.
9. What does the 'len' function return when applied to an array in Go?
Answer:
Explanation:
The 'len' function in Go returns the number of elements in the array.
10. How can you iterate over an array in Go?
Answer:
Explanation:
The 'range' keyword is used in Go to iterate over elements of an array.
11. What is the default value of elements in an array of type bool in Go?
Answer:
Explanation:
The default zero value for boolean types in Go, including elements in a boolean array, is 'false'.
12. How do you declare a multi-dimensional array in Go?
Answer:
Explanation:
Multi-dimensional arrays in Go are declared by specifying the size of each dimension in square brackets.
13. Is it possible to compare two arrays directly in Go?
Answer:
Explanation:
In Go, two arrays can be compared directly using the '==' operator if they are of the same type and size.
14. How can you copy an array into another array in Go?
Answer:
Explanation:
The 'copy()' function is used in Go to copy elements from one array to another.
15. What is the output of the 'cap' function when applied to an array in Go?
Answer:
Explanation:
The 'cap' function in Go returns the capacity of the array, which is the number of elements it can contain.