Challenge - 5 Problems
Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array element modification
What is the output of this C program?
C
#include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; arr[2] = arr[0] + arr[4]; printf("%d\n", arr[2]); return 0; }
Attempts:
2 left
💡 Hint
Remember array indexing starts at 0. arr[2] is changed to arr[0] + arr[4].
✗ Incorrect
arr[0] is 1 and arr[4] is 5, so arr[2] becomes 1 + 5 = 6.
❓ Predict Output
intermediate2:00remaining
Sum of elements in an array
What is the output of this C program?
C
#include <stdio.h> int main() { int nums[] = {10, 20, 30, 40}; int sum = 0; for(int i = 0; i < 4; i++) { sum += nums[i]; } printf("%d\n", sum); return 0; }
Attempts:
2 left
💡 Hint
Add all elements: 10 + 20 + 30 + 40.
✗ Incorrect
The sum is 10 + 20 + 30 + 40 = 100.
🔧 Debug
advanced2:00remaining
Identify the error in array access
What error will this C program produce when run?
C
#include <stdio.h> int main() { int arr[3] = {1, 2, 3}; printf("%d\n", arr[3]); return 0; }
Attempts:
2 left
💡 Hint
Array indices go from 0 to size-1. Accessing arr[3] is outside the array.
✗ Incorrect
Accessing arr[3] is out of bounds and causes undefined behavior. The program may print garbage or crash, but no compile error occurs.
📝 Syntax
advanced2:00remaining
Which option causes a compilation error?
Which of the following array declarations will cause a compilation error in C?
Attempts:
2 left
💡 Hint
Check if the initializer list fits the declared array size.
✗ Incorrect
Option A tries to initialize an array of size 3 with 4 elements, which is a compilation error.
🚀 Application
expert2:00remaining
Find the number of elements in the array
What is the value of 'count' after running this C program?
C
#include <stdio.h> int main() { int data[] = {5, 10, 15, 20, 25, 30}; int count = sizeof(data) / sizeof(data[0]); printf("%d\n", count); return 0; }
Attempts:
2 left
💡 Hint
sizeof(data) gives total bytes, sizeof(data[0]) gives bytes per element.
✗ Incorrect
The array has 6 elements. Dividing total size by element size gives 6.