Challenge - 5 Problems
Go Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array length and values
What is the output of this Go program?
Go
package main import "fmt" func main() { var arr [3]int = [3]int{1, 2, 3} fmt.Println(len(arr)) fmt.Println(arr[1]) }
Attempts:
2 left
💡 Hint
Remember that len(arr) returns the number of elements, and indexing starts at 0.
✗ Incorrect
The array has 3 elements, so len(arr) is 3. The element at index 1 is the second element, which is 2.
❓ Predict Output
intermediate2:00remaining
Array default values
What will this Go program print?
Go
package main import "fmt" func main() { var arr [4]int fmt.Println(arr[2]) }
Attempts:
2 left
💡 Hint
Uninitialized int array elements have a default value.
✗ Incorrect
In Go, arrays of int type are initialized with zero values, so arr[2] is 0.
📝 Syntax
advanced2:00remaining
Identify the correct array declaration
Which option correctly declares an array of 5 strings in Go?
Attempts:
2 left
💡 Hint
Arrays have fixed size and type in Go, slices are different.
✗ Incorrect
Option B declares a fixed-size array of 5 strings. Option B is invalid syntax because it lacks the type after :=. Option B declares a slice, not an array. Option B has wrong syntax for array type.
❓ Predict Output
advanced2:00remaining
Array initialization and zero values
What is the output of this Go program?
Go
package main import "fmt" func main() { arr := [4]int{1, 2} fmt.Println(arr[2]) }
Attempts:
2 left
💡 Hint
Uninitialized elements in an array get zero values.
✗ Incorrect
The array has 4 elements, only first two initialized. The third element (index 2) is zero by default.
🧠 Conceptual
expert3:00remaining
Array vs Slice declaration difference
Which option correctly describes the difference between arrays and slices in Go?
Attempts:
2 left
💡 Hint
Think about size and mutability differences.
✗ Incorrect
Arrays have fixed size and store elements directly. Slices are dynamic, can grow, and reference underlying arrays.