Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the element at index 2 in the array.
DSA C
int arr[] = {10, 20, 30, 40, 50};
int value = arr[[1]];
printf("%d\n", value); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 or 4 which accesses wrong elements.
Forgetting that array indexes start at 0.
✗ Incorrect
The index 2 accesses the third element in the array, which is 30.
2fill in blank
mediumComplete the code to update the element at index 1 to 100.
DSA C
int arr[] = {5, 10, 15, 20};
arr[[1]] = 100;
printf("%d\n", arr[1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Updating the wrong index like 0 or 2.
Confusing index with the value.
✗ Incorrect
Index 1 corresponds to the second element, which we update to 100.
3fill in blank
hardFix the error in the code to correctly update the last element of the array.
DSA C
int arr[] = {1, 2, 3, 4, 5};
int n = 5;
arr[[1]] = 50;
printf("%d\n", arr[4]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using n as index which is out of bounds.
Using 5 as index which is invalid.
✗ Incorrect
The last element is at index n - 1 because indexing starts at 0.
4fill in blank
hardFill both blanks to print the updated value at index 3 after setting it to 99.
DSA C
int arr[] = {7, 8, 9, 10, 11};
arr[[1]] = 99;
printf("%d\n", arr[[2]]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different indexes for update and print.
Using out of range indexes.
✗ Incorrect
Index 3 is updated to 99 and then printed from the same index.
5fill in blank
hardFill all three blanks to update the element at index 0 to 42, then print it.
DSA C
int arr[] = {0, 1, 2, 3};
arr[[1]] = [2];
printf("%d\n", arr[[3]]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong index for update or print.
Using wrong value for update.
✗ Incorrect
We update index 0 to 42 and then print the value at index 0.
