Challenge - 5 Problems
Array Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of code using arrays for storing multiple values
What is the output of this C program that uses an array to store multiple numbers and prints them?
C
#include <stdio.h> int main() { int numbers[3] = {10, 20, 30}; for (int i = 0; i < 3; i++) { printf("%d ", numbers[i]); } return 0; }
Attempts:
2 left
💡 Hint
Look at how many elements are in the array and how many times the loop runs.
✗ Incorrect
The array 'numbers' holds exactly 3 integers: 10, 20, and 30. The loop runs 3 times, printing each element followed by a space.
🧠 Conceptual
intermediate1:30remaining
Why use arrays instead of separate variables?
Why are arrays useful compared to using many separate variables for similar data?
Attempts:
2 left
💡 Hint
Think about how you would handle a list of scores or names.
✗ Incorrect
Arrays group related data under one name and allow easy access by position, which is simpler than declaring many separate variables.
🔧 Debug
advanced2:00remaining
Identify the error in array usage
What error will this C code produce when compiled or run?
C
#include <stdio.h> int main() { int arr[2] = {1, 2, 3}; printf("%d", arr[2]); return 0; }
Attempts:
2 left
💡 Hint
Check how many elements the array can hold versus how many values are given.
✗ Incorrect
The array is declared to hold 2 integers but initialized with 3 values, which causes a compilation error in C.
❓ Predict Output
advanced2:00remaining
Output when accessing array elements beyond size
What will this C program output?
C
#include <stdio.h> int main() { int nums[3] = {5, 10, 15}; printf("%d", nums[3]); return 0; }
Attempts:
2 left
💡 Hint
Array indices start at 0 and go up to size-1.
✗ Incorrect
Accessing nums[3] is out of bounds since valid indices are 0,1,2. This causes undefined behavior in C.
🚀 Application
expert2:30remaining
How arrays help in storing multiple related data
You want to store the daily temperatures for a week. Which statement best explains why arrays are needed here?
Attempts:
2 left
💡 Hint
Think about how you would keep track of multiple values that belong together.
✗ Incorrect
Arrays group multiple related values under one name and allow easy access by index, which is perfect for storing daily temperatures.