0
0
Goprogramming~10 mins

Array declaration 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
[1] numbers [5]int
Drag options to blanks, or click blank then click option'
Avar
B=
C:=
Dconst
Attempts:
3 left
💡 Hint
Common Mistakes
Using := to declare an array type
Using = sign between variable name and type
Using const keyword for array declaration
2fill in blank
medium

Complete the code to declare and initialize an array of 3 strings.

Go
var fruits = [1]string{"apple", "banana", "cherry"}
Drag options to blanks, or click blank then click option'
A[]
B[3]
Cmake
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using []string instead of [3]string for array
Using make function for array initialization
Using {} without type declaration
3fill in blank
hard

Fix the error in the array declaration to create an array of 4 floats.

Go
var values = [1]float64{1.1, 2.2, 3.3, 4.4}
Drag options to blanks, or click blank then click option'
A[]
B(4)
C[4]
D{4}
Attempts:
3 left
💡 Hint
Common Mistakes
Using []float64 which declares a slice, not an array
Using parentheses or braces for size
Omitting the size
4fill in blank
hard

Fill the blank to declare an array of 2 booleans and initialize it with true and false.

Go
var flags [1]bool = {true, false}
Drag options to blanks, or click blank then click option'
A[2]
B[3]
C[]
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using []bool which declares a slice
Using parentheses instead of curly braces for initialization
Mismatching array size and number of elements
5fill in blank
hard

Fill both blanks to declare and initialize an array of 3 integers with values 10, 20, and 30.

Go
var nums [1]int = [2]
Drag options to blanks, or click blank then click option'
A[3]
B[4]
C{10, 20, 30}
D{10, 20, 30, 40}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong array size
Including more elements than the size
Using slice syntax instead of array