0
0
C++programming~10 mins

Array initialization in C++ - 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 integer array named numbers with 5 elements.

C++
int numbers[[1]];
Drag options to blanks, or click blank then click option'
A5
Bsize
C0
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name instead of a number inside the brackets.
Leaving the brackets empty.
Using zero as the size.
2fill in blank
medium

Complete the code to initialize the array numbers with values 1, 2, 3, 4, 5.

C++
int numbers[5] = [1];
Drag options to blanks, or click blank then click option'
A"1, 2, 3, 4, 5"
B[1, 2, 3, 4, 5]
C(1, 2, 3, 4, 5)
D{1, 2, 3, 4, 5}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of curly braces.
Using parentheses instead of curly braces.
Using a string instead of a list of values.
3fill in blank
hard

Fix the error in the array initialization to correctly initialize an array of 3 floats with values 1.1, 2.2, 3.3.

C++
float values[3] = [1];
Drag options to blanks, or click blank then click option'
A(1.1, 2.2, 3.3)
B[1.1, 2.2, 3.3]
C{1.1, 2.2, 3.3}
D"1.1, 2.2, 3.3"
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Using a string literal instead of a list of values.
4fill in blank
hard

Fill both blanks to declare and initialize an array of 4 characters with letters 'a', 'b', 'c', 'd'.

C++
char letters[[1]] = [2];
Drag options to blanks, or click blank then click option'
A4
B5
C{'a', 'b', 'c', 'd'}
D{'a', 'b', 'c', 'd', 'e'}
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between array size and number of elements.
Using double quotes instead of single quotes for characters.
5fill in blank
hard

Fill all three blanks to declare and initialize an integer array named scores with 3 elements: 10, 20, 30.

C++
int [1][[2]] = [3];
Drag options to blanks, or click blank then click option'
Ascores
B3
C{10, 20, 30}
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong array name.
Mismatch between size and number of elements.
Using parentheses or square brackets for initialization.