Challenge - 5 Problems
Array Initialization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array initialization with default values
What is the output of this Go program?
package main
import "fmt"
func main() {
var arr [4]int
fmt.Println(arr)
}Go
package main import "fmt" func main() { var arr [4]int fmt.Println(arr) }
Attempts:
2 left
💡 Hint
In Go, arrays of integers are initialized with zero values by default.
✗ Incorrect
When you declare an array of integers without assigning values, Go fills it with zeros.
❓ Predict Output
intermediate2:00remaining
Output of array initialization with explicit values
What does this Go program print?
package main
import "fmt"
func main() {
arr := [3]string{"go", "lang", "rocks"}
fmt.Println(arr)
}Go
package main import "fmt" func main() { arr := [3]string{"go", "lang", "rocks"} fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Arrays print their elements separated by spaces inside square brackets.
✗ Incorrect
The array is initialized with three strings and prints exactly those elements.
❓ Predict Output
advanced2:00remaining
Output of partially initialized array
What is the output of this Go program?
package main
import "fmt"
func main() {
arr := [5]int{1, 2}
fmt.Println(arr)
}Go
package main import "fmt" func main() { arr := [5]int{1, 2} fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Uninitialized elements in an array get zero values.
✗ Incorrect
Only the first two elements are set; the rest default to zero.
❓ Predict Output
advanced2:00remaining
Output of array initialization with index keys
What does this Go program print?
package main
import "fmt"
func main() {
arr := [4]int{1: 10, 3: 30}
fmt.Println(arr)
}Go
package main import "fmt" func main() { arr := [4]int{1: 10, 3: 30} fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Elements not explicitly set get zero values.
✗ Incorrect
Only indexes 1 and 3 are set; others are zero.
🧠 Conceptual
expert2:00remaining
Length of array initialized with ellipsis
What is the length of the array declared in this Go code?
arr := [...]int{5, 10, 15, 20}Go
package main import "fmt" func main() { arr := [...]int{5, 10, 15, 20} fmt.Println(len(arr)) }
Attempts:
2 left
💡 Hint
The ellipsis lets Go count the elements automatically.
✗ Incorrect
The array length is the number of elements inside the braces.