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 array sum calculation
What is the output of this C++ code that sums elements of an array?
C++
#include <iostream> int main() { int arr[5] = {1, 2, 3, 4, 5}; int sum = 0; for(int i = 0; i < 5; i++) { sum += arr[i]; } std::cout << sum << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Add all numbers from 1 to 5.
✗ Incorrect
The loop adds all elements: 1+2+3+4+5 = 15.
❓ Predict Output
intermediate2:00remaining
Value of array element after modification
What is the value of arr[2] after running this code?
C++
#include <iostream> int main() { int arr[4] = {10, 20, 30, 40}; arr[2] = arr[1] + arr[3]; std::cout << arr[2] << std::endl; return 0; }
Attempts:
2 left
💡 Hint
arr[2] is set to arr[1] + arr[3].
✗ Incorrect
arr[1] is 20 and arr[3] is 40, so arr[2] becomes 60.
🔧 Debug
advanced2:00remaining
Identify the error in array initialization
What error does this code produce?
C++
#include <iostream> int main() { int arr[3] = {1, 2, 3, 4}; std::cout << arr[0] << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Array size is 3 but 4 values are given.
✗ Incorrect
The array is declared with size 3 but initialized with 4 values, causing a compilation error.
📝 Syntax
advanced2:00remaining
Correct syntax to declare and initialize an array
Which option correctly declares and initializes an array of 4 integers with values 5, 10, 15, 20?
Attempts:
2 left
💡 Hint
Use curly braces and specify size correctly.
✗ Incorrect
Option A correctly declares an array of size 4 and initializes it with 4 values using curly braces.
🚀 Application
expert2:00remaining
Find the number of elements greater than 10
What is the output of this program that counts elements greater than 10 in an array?
C++
#include <iostream> int main() { int arr[6] = {5, 12, 7, 18, 10, 20}; int count = 0; for(int i = 0; i < 6; i++) { if(arr[i] > 10) { count++; } } std::cout << count << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Count how many numbers are strictly greater than 10.
✗ Incorrect
The numbers greater than 10 are 12, 18, and 20, so count is 3.