Bird
0
0
DSA Cprogramming~20 mins

Array Declaration and Initialization in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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]);
}
A1 2 0 0 1
B1 2 3 4 5
C1 2 0 0 0
D1 2 2 2 2
Attempts:
2 left
💡 Hint
Uninitialized elements in a partially initialized array are set to zero.
Predict Output
intermediate
2: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]);
}
A5 10 15
B5 10 15 0
C0 0 0
D15 10 5
Attempts:
2 left
💡 Hint
All elements are explicitly initialized.
Predict Output
advanced
2: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]);
}
A7 8 9 10
B7 8 9 10 0
C0 0 0 0
D10 9 8 7
Attempts:
2 left
💡 Hint
Array size is inferred from initializer list.
Predict Output
advanced
2: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]);
    }
}
A1 2 3 4 5 6
B1 2 3 4 0 0
C1 2 3 4 4 4
D1 2 3 0 0 0
Attempts:
2 left
💡 Hint
Uninitialized elements in inner arrays are zero.
🧠 Conceptual
expert
2:00remaining
Size of array with partial initialization and no explicit size
Consider the declaration:
int arr[] = {3, 6, 9};
What is the size of the array arr in memory?
ADepends on compiler
B0
CSize must be explicitly specified
D3
Attempts:
2 left
💡 Hint
When size is omitted, it is inferred from initializer list length.