0
0
Goprogramming~20 mins

Array declaration in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Go Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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])
}
A
3
0
B
3
1
C
3
2
D
2
2
Attempts:
2 left
💡 Hint
Remember that len(arr) returns the number of elements, and indexing starts at 0.
Predict Output
intermediate
2: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])
}
Aundefined
B2
Cnil
D0
Attempts:
2 left
💡 Hint
Uninitialized int array elements have a default value.
📝 Syntax
advanced
2:00remaining
Identify the correct array declaration
Which option correctly declares an array of 5 strings in Go?
Aarr := [5]string{}
Bvar arr [5]string
Cvar arr []string = make([]string, 5)
Dvar arr [5] = string{}
Attempts:
2 left
💡 Hint
Arrays have fixed size and type in Go, slices are different.
Predict Output
advanced
2: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])
}
A0
B2
Cruntime error
D3
Attempts:
2 left
💡 Hint
Uninitialized elements in an array get zero values.
🧠 Conceptual
expert
3:00remaining
Array vs Slice declaration difference
Which option correctly describes the difference between arrays and slices in Go?
AArrays have fixed size known at compile time; slices are dynamic and reference arrays.
BSlices have fixed size; arrays can grow dynamically.
CArrays and slices are the same in Go, just different names.
DArrays are pointers to slices internally.
Attempts:
2 left
💡 Hint
Think about size and mutability differences.