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 partially initialized array
What is the output of the following C code snippet?
DSA C
int arr[5] = {1, 2}; for (int i = 0; i < 5; i++) { printf("%d ", arr[i]); }
Attempts:
2 left
💡 Hint
Uninitialized elements in a partially initialized array are set to zero.
✗ Incorrect
In C, when you initialize an array with fewer elements than its size, the remaining elements are set to zero.
So arr[0] = 1, arr[1] = 2, and arr[2], arr[3], arr[4] = 0.
❓ Predict Output
intermediate2:00remaining
Output of array initialization with explicit size and values
What is the output of this C code?
DSA C
int arr[3] = {5, 10, 15}; for (int i = 0; i < 3; i++) { printf("%d ", arr[i]); }
Attempts:
2 left
💡 Hint
All elements are explicitly initialized.
✗ Incorrect
The array has size 3 and all elements are initialized explicitly.
So the output prints 5, 10, and 15 in order.
❓ Predict Output
advanced2:00remaining
Output of array without explicit size but with initialization
What will be printed by this C code?
DSA C
int arr[] = {7, 8, 9, 10}; for (int i = 0; i < 4; i++) { printf("%d ", arr[i]); }
Attempts:
2 left
💡 Hint
Array size is inferred from initializer list.
✗ Incorrect
When size is omitted, the compiler sets the array size to the number of initializer elements.
So arr has size 4 with values 7,8,9,10.
❓ Predict Output
advanced2:00remaining
Output of multi-dimensional array initialization
What is the output of this C code snippet?
DSA C
int arr[2][3] = {{1, 2, 3}, {4}}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { printf("%d ", arr[i][j]); } }
Attempts:
2 left
💡 Hint
Uninitialized elements in inner arrays are zero.
✗ Incorrect
The first row is fully initialized: 1, 2, 3.
The second row has only the first element initialized to 4; the rest are zero.
🧠 Conceptual
expert2:00remaining
Size of array with partial initialization and no explicit size
Consider the declaration:
What is the size of the array
int arr[] = {3, 6, 9};What is the size of the array
arr in memory?Attempts:
2 left
💡 Hint
When size is omitted, it is inferred from initializer list length.
✗ Incorrect
The compiler counts the number of elements in the initializer list and sets the array size accordingly.
Here, 3 elements means size 3.
