Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an array of 5 integers.
C
int numbers[[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.
Using a size larger than needed.
✗ Incorrect
The array size must be 5 to hold exactly 5 integers.
2fill in blank
mediumComplete the code to access the third element of the array.
C
int third = numbers[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as index which is out of bounds for third element.
Confusing element number with index.
✗ Incorrect
Array indexes start at 0, so the third element is at index 2.
3fill in blank
hardFix the error in the code to avoid accessing out of bounds.
C
for (int i = 0; i < [1]; i++) { printf("%d\n", numbers[i]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using i <= 5 which tries to access numbers[5] out of bounds.
Using a larger number than array size.
✗ Incorrect
The loop should run while i is less than 5 to stay within array bounds.
4fill in blank
hardFill both blanks to create an array of 4 integers and assign 10 to the last element.
C
int arr[[1]]; arr[[2]] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 4 which is out of bounds for size 4.
Using size 3 which is too small.
✗ Incorrect
The array size is 4, so the last element index is 3 (since indexing starts at 0).
5fill in blank
hardFill all three blanks to declare an array of 6 integers, assign 20 to the first element, and print it.
C
int nums[[1]]; nums[[2]] = 20; printf("%d\n", nums[[3]]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 or 5 instead of 0 for first element.
Using wrong array size.
✗ Incorrect
The array size is 6. The first element is at index 0, so assign and print nums[0].