0
0
Goprogramming~10 mins

Array limitations in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an array of 5 integers.

Go
var numbers [[1]]int
Drag options to blanks, or click blank then click option'
A5
B0
C10
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as the size, which creates an array of zero length.
Using a variable instead of a constant for the array size.
2fill in blank
medium

Complete the code to access the third element of the array named 'data'.

Go
value := data[[1]]
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as the index, which is actually the fourth element.
Using 1 or 0 which refer to earlier elements.
3fill in blank
hard

Fix the error in the code to declare an array with a variable size 'n'.

Go
var arr [[1]]int

// n is a variable
n := 10
Drag options to blanks, or click blank then click option'
An
Bvar n
C10
Dlen(arr)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable 'n' directly as the array size.
Trying to use len(arr) before arr is declared.
4fill in blank
hard

Fill both blanks to create a fixed-size array and assign a value to its first element.

Go
var arr [[1]]int
arr[[2]] = 100
Drag options to blanks, or click blank then click option'
A4
B5
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as the array size.
Using 1 as the first element index.
5fill in blank
hard

Fill all three blanks to declare an array, assign a value, and print the length.

Go
var arr [[1]]int
arr[[2]] = 42
fmt.Println(len(arr) == [3])
Drag options to blanks, or click blank then click option'
A3
B0
C5
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using an index equal to the size (out of bounds).
Confusing array length with last index.