0
0
Cprogramming~10 mins

Common array operations - 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 of size 5.

C
int arr[[1]];
Drag options to blanks, or click blank then click option'
A5
B10
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero as the size, which is invalid.
Forgetting to specify the size.
2fill in blank
medium

Complete 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'
A1
B0
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 2 for the third element index.
Using 1 which is the second element.
3fill in blank
hard

Fix 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'
A4
B3
C5
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 causes out-of-bounds access.
Using 3 misses the last element.
4fill in blank
hard

Fill 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'
Ai
B6
Cn
Dj
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.
5fill in blank
hard

Fill 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'
Aint
Carr[0]
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types for declaration and initialization.
Trying to print the whole array instead of one element.