Challenge - 5 Problems
Array Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output after updating an array element?
Consider the following C code that updates an element in an array. What will be the printed output?
DSA C
int arr[5] = {10, 20, 30, 40, 50}; arr[2] = 100; for(int i = 0; i < 5; i++) { printf("%d ", arr[i]); }
Attempts:
2 left
💡 Hint
Remember that array indices start at 0, so arr[2] is the third element.
✗ Incorrect
The code changes the third element (index 2) from 30 to 100. The rest remain unchanged.
❓ Predict Output
intermediate2:00remaining
What happens when accessing an array out of bounds?
What is the output or behavior of this C code snippet?
DSA C
int arr[3] = {1, 2, 3}; printf("%d", arr[5]);
Attempts:
2 left
💡 Hint
Accessing outside the array size is not safe in C.
✗ Incorrect
Accessing arr[5] goes beyond the allocated array size, causing undefined behavior.
🔧 Debug
advanced2:00remaining
Identify the error in updating array elements
What error will this C code produce when compiled or run?
DSA C
int arr[4] = {5, 10, 15, 20}; arr[4] = 25; printf("%d", arr[4]);
Attempts:
2 left
💡 Hint
Array indices go from 0 to size-1.
✗ Incorrect
The code compiles but accessing arr[4] is out of bounds causing undefined behavior.
❓ Predict Output
advanced2:00remaining
What is the final array after multiple updates?
Given the following code, what is the final printed array?
DSA C
int arr[5] = {1, 2, 3, 4, 5}; arr[0] = arr[4]; arr[4] = arr[1]; arr[1] = 10; for(int i = 0; i < 5; i++) { printf("%d ", arr[i]); }
Attempts:
2 left
💡 Hint
Track each assignment step by step.
✗ Incorrect
arr[0] becomes 5 (old arr[4]), arr[4] becomes 2 (old arr[1]), arr[1] becomes 10.
🧠 Conceptual
expert2:00remaining
How many elements are in the array after this declaration?
What is the number of elements in this array in C?
DSA C
int arr[] = {7, 14, 21, 28, 35, 42};
Attempts:
2 left
💡 Hint
When size is omitted, the compiler counts the initializer elements.
✗ Incorrect
The array has 6 elements because 6 values are given in the initializer.
