0
0
Cprogramming~20 mins

One-dimensional arrays in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of array element modification
What is the output of this C program?
C
#include <stdio.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    arr[2] = arr[0] + arr[4];
    printf("%d\n", arr[2]);
    return 0;
}
A3
B5
C6
D9
Attempts:
2 left
💡 Hint
Remember array indexing starts at 0. arr[2] is changed to arr[0] + arr[4].
Predict Output
intermediate
2:00remaining
Sum of elements in an array
What is the output of this C program?
C
#include <stdio.h>

int main() {
    int nums[] = {10, 20, 30, 40};
    int sum = 0;
    for(int i = 0; i < 4; i++) {
        sum += nums[i];
    }
    printf("%d\n", sum);
    return 0;
}
A40
B100
C90
D10
Attempts:
2 left
💡 Hint
Add all elements: 10 + 20 + 30 + 40.
🔧 Debug
advanced
2:00remaining
Identify the error in array access
What error will this C program produce when run?
C
#include <stdio.h>

int main() {
    int arr[3] = {1, 2, 3};
    printf("%d\n", arr[3]);
    return 0;
}
AUndefined behavior (out-of-bounds access)
BCompilation error: array index out of range
CRuntime error: segmentation fault
DPrints 0
Attempts:
2 left
💡 Hint
Array indices go from 0 to size-1. Accessing arr[3] is outside the array.
📝 Syntax
advanced
2:00remaining
Which option causes a compilation error?
Which of the following array declarations will cause a compilation error in C?
Aint arr[3] = {1, 2, 3, 4};
Bint arr[] = {1, 2, 3, 4, 5};
Cint arr[5] = {1, 2, 3, 4, 5};
Dint arr[5];
Attempts:
2 left
💡 Hint
Check if the initializer list fits the declared array size.
🚀 Application
expert
2:00remaining
Find the number of elements in the array
What is the value of 'count' after running this C program?
C
#include <stdio.h>

int main() {
    int data[] = {5, 10, 15, 20, 25, 30};
    int count = sizeof(data) / sizeof(data[0]);
    printf("%d\n", count);
    return 0;
}
A4
B5
C24
D6
Attempts:
2 left
💡 Hint
sizeof(data) gives total bytes, sizeof(data[0]) gives bytes per element.