Challenge - 5 Problems
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of storing multiple values without arrays
Consider the following C++ code that tries to store multiple scores without using arrays. What will be the output?
C++
#include <iostream> using namespace std; int main() { int score1 = 90; int score2 = 85; int score3 = 78; cout << score1 << ", " << score2 << ", " << score3 << endl; return 0; }
Attempts:
2 left
💡 Hint
Look at how the values are printed with commas and spaces.
✗ Incorrect
The code prints the three scores separated by commas and spaces exactly as coded.
🧠 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 items easily.
✗ Incorrect
Arrays group multiple values under one name and let you access each value by its position, making code simpler and easier to manage.
❓ Predict Output
advanced2:00remaining
Output of array initialization and access
What is the output of this C++ program that uses an array to store numbers?
C++
#include <iostream> using namespace std; int main() { int numbers[4] = {10, 20, 30, 40}; cout << numbers[1] + numbers[3] << endl; return 0; }
Attempts:
2 left
💡 Hint
Remember array indexing starts at 0.
✗ Incorrect
numbers[1] is 20 and numbers[3] is 40, their sum is 60.
❓ Predict Output
advanced2:00remaining
What happens if you access array out of bounds?
What will happen if you run this C++ code?
C++
#include <iostream> using namespace std; int main() { int arr[3] = {1, 2, 3}; cout << arr[5] << endl; return 0; }
Attempts:
2 left
💡 Hint
Think about what happens when you access memory outside the array.
✗ Incorrect
Accessing outside the array size is undefined behavior; it may print garbage or unpredictable values but usually does not cause a compile or runtime error.
🧠 Conceptual
expert2:30remaining
Why arrays improve code scalability?
How do arrays help make programs easier to scale when dealing with many similar items?
Attempts:
2 left
💡 Hint
Think about how loops and arrays work together.
✗ Incorrect
Arrays let you store many items in one place and use loops to handle them all, so you don't need to write code for each item separately.