Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an integer array of size 5.
C
int arr[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero as the size, which is invalid.
Forgetting to specify the size.
✗ Incorrect
The code declares an integer array named arr with 5 elements.
2fill in blank
mediumComplete the code to access the third element of the array.
C
int value = arr[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for the third element index.
Using 1 which is the second element.
✗ Incorrect
Array indexes start at 0, so the third element is at index 2.
3fill in blank
hardFix the error in the loop to print all elements of the array of size 4.
C
for(int i = 0; i < [1]; i++) { printf("%d\n", arr[i]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 causes out-of-bounds access.
Using 3 misses the last element.
✗ Incorrect
The loop should run while i is less than the array size, which is 4.
4fill in blank
hardFill both blanks to create a loop that sums all elements in an array named nums of size 6.
C
int sum = 0; for(int [1] = 0; [1] < [2]; [1]++) { sum += nums[[1]]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not declared in the loop.
Using a wrong loop limit causing out-of-bounds access.
✗ Incorrect
Variable i is commonly used as a loop counter. The loop runs while i < 6 to cover all elements.
5fill in blank
hardFill both blanks to declare an array, initialize it, and print its first element.
C
[1] arr[3] = {1, 2, 3}; printf("%d\n", [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types for declaration and initialization.
Trying to print the whole array instead of one element.
✗ Incorrect
The array is declared as int arr[3], initialized with values, and the first element arr[0] is printed.