0
0
Goprogramming~10 mins

Array initialization 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 [5]int = [1]
Drag options to blanks, or click blank then click option'
Aarray{1, 2, 3, 4, 5}
B[5]int(1, 2, 3, 4, 5)
C[]int{1, 2, 3, 4, 5}
D[5]int{1, 2, 3, 4, 5}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for initialization.
Using slice syntax instead of array syntax.
Omitting the size inside the square brackets.
2fill in blank
medium

Complete the code to declare an array of 3 strings with default zero values.

Go
var fruits [1]
Drag options to blanks, or click blank then click option'
A[]string
B[3]string
Carray[3]string
Dstring[3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice syntax instead of array syntax.
Writing the type before the size.
Using invalid syntax like 'array[3]string'.
3fill in blank
hard

Fix the error in the array initialization syntax.

Go
var primes = [1]int{2, 3, 5, 7, 11}
Drag options to blanks, or click blank then click option'
A[5]
B(5)
D{5}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for size.
Omitting the size entirely.
Using curly braces for size.
4fill in blank
hard

Fill both blanks to create an array of 4 floats initialized with values.

Go
var scores [1] = [2]{98.5, 87.0, 92.3, 88.8}}
Drag options to blanks, or click blank then click option'
A[4]float64
B[]float64
C[4]
Dfloat64
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice syntax for the value initialization.
Omitting the size in the value initialization.
Using the type name alone without size in the value.
5fill in blank
hard

Fill all three blanks to declare and initialize an array of 3 booleans with true, false, true.

Go
var flags [1] = [2][3]
Drag options to blanks, or click blank then click option'
A[3]bool
B[3]
C{true, false, true}
D[]bool
Attempts:
3 left
💡 Hint
Common Mistakes
Using slice syntax instead of array syntax.
Omitting the size in the value initialization.
Using parentheses instead of curly braces for values.