Bird
0
0
DSA Cprogramming~20 mins

Array Insertion at End in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Insertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output after inserting an element at the end?
Consider the following C code that inserts an element at the end of an array. What will be printed after insertion?
DSA C
int main() {
    int arr[5] = {1, 2, 3, 4};
    int size = 4;
    int capacity = 5;
    int element = 10;

    if (size < capacity) {
        arr[size] = element;
        size++;
    }

    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
A1 2 3 4
B1 2 3 4 0
C10 1 2 3 4
D1 2 3 4 10
Attempts:
2 left
💡 Hint
Think about how the element is added and how the size changes.
Predict Output
intermediate
2:00remaining
What happens if we insert beyond array capacity?
What will be the output of this C code snippet?
DSA C
int main() {
    int arr[3] = {5, 6, 7};
    int size = 3;
    int capacity = 3;
    int element = 9;

    if (size < capacity) {
        arr[size] = element;
        size++;
    }

    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
A5 6 7
B5 6 7 9
C9 5 6 7
D5 6 7 0
Attempts:
2 left
💡 Hint
Check the condition before insertion carefully.
🔧 Debug
advanced
2:00remaining
Why does this insertion code cause unexpected output?
Identify the problem in this code that inserts an element at the end of an array and prints it.
DSA C
int main() {
    int arr[4] = {1, 2, 3};
    int size = 3;
    int capacity = 4;
    int element = 8;

    arr[size] = element;
    // Missing size increment here

    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
AOutput: 1 2 3
BOutput: 1 2 3 8
COutput: 1 2 3 0
DRuntime error due to out of bounds
Attempts:
2 left
💡 Hint
Check if the size variable is updated after insertion.
Predict Output
advanced
2:00remaining
What is the output after multiple insertions at the end?
Given the following code, what will be printed?
DSA C
int main() {
    int arr[6] = {2, 4, 6};
    int size = 3;
    int capacity = 6;
    int elements_to_add[3] = {8, 10, 12};

    for (int i = 0; i < 3; i++) {
        if (size < capacity) {
            arr[size] = elements_to_add[i];
            size++;
        }
    }

    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
A2 4 6 8 10
B2 4 6 8 10 12
C2 4 6 0 0 0
D8 10 12 2 4 6
Attempts:
2 left
💡 Hint
Look at how the loop adds elements and updates size.
🧠 Conceptual
expert
2:00remaining
What is the main limitation of inserting at the end of a static array?
Why can inserting an element at the end of a static array fail or be limited?
ABecause the array automatically resizes causing slow insertion
BBecause elements must be shifted to insert at the end
CBecause the array size is fixed and cannot grow beyond its capacity
DBecause inserting at the end requires sorting the array
Attempts:
2 left
💡 Hint
Think about the difference between static and dynamic arrays.