0
0
Cprogramming~10 mins

Array size and bounds 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 array of 5 integers.

C
int numbers[[1]];
Drag options to blanks, or click blank then click option'
A5
B10
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as size which creates an empty array.
Using a size larger than needed.
2fill in blank
medium

Complete 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'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as index which is out of bounds for third element.
Confusing element number with index.
3fill in blank
hard

Fix 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'
A0
B5
C10
D6
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.
4fill in blank
hard

Fill 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'
A4
B3
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 4 which is out of bounds for size 4.
Using size 3 which is too small.
5fill in blank
hard

Fill 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'
A6
B0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 or 5 instead of 0 for first element.
Using wrong array size.