Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an array of 5 integers.
C++
int arr[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as size which creates an empty array.
Forgetting to specify the size.
✗ Incorrect
The array size must be specified as 5 to create an array with 5 elements.
2fill in blank
mediumComplete the code to assign the value 10 to the first element of the array.
C++
arr[[1]] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the first index.
Using negative indices which are invalid.
✗ Incorrect
Array indexing in C++ starts at 0, so the first element is at index 0.
3fill in blank
hardFix the error in the code to correctly print the third element of the array.
C++
std::cout << arr[[1]] << std::endl; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 which is the fourth element.
Using index 1 which is the second element.
✗ Incorrect
The third element is at index 2 because indexing starts at 0.
4fill in blank
hardFill both blanks to create an array of 4 integers and assign 7 to its last element.
C++
int arr[[1]]; arr[[2]] = 7;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 4 which is out of bounds.
Using size 5 instead of 4.
✗ Incorrect
The array size is 4, so the last element is at index 3 (4 - 1).
5fill in blank
hardFill all three blanks to initialize an array with values 1, 2, 3 and print the second element.
C++
int arr[[1]] = {1, 2, 3}; std::cout << arr[[2]] << std::endl; int size = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong size for the array.
Using wrong index to print the second element.
✗ Incorrect
The array size is 3, the second element is at index 1, and size is 3.