0
0
Cprogramming~20 mins

Array of structures - Practice Problems & Coding Challenges

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

struct Point {
    int x;
    int y;
};

int main() {
    struct Point points[3] = {{1, 2}, {3, 4}, {5, 6}};
    printf("%d %d\n", points[1].x, points[1].y);
    return 0;
}
ACompilation error
B3 4
C5 6
D1 2
Attempts:
2 left
💡 Hint
Remember that array indexing starts at 0.
🧠 Conceptual
intermediate
2:00remaining
Size of array of structures
Given the following structure and array declaration, what is the size in bytes of the array 'employees' on a system where int is 4 bytes and char is 1 byte, assuming no padding?
C
struct Employee {
    int id;
    char grade;
};

struct Employee employees[5];
A20 bytes
BDepends on compiler padding
C30 bytes
D25 bytes
Attempts:
2 left
💡 Hint
Calculate size of one structure and multiply by array length.
🔧 Debug
advanced
2:00remaining
Identify the error in array of structures initialization
What error will this code produce?
C
struct Data {
    int a;
    int b;
};

int main() {
    struct Data arr[2] = {1, 2, 3, 4};
    return 0;
}
ARuns and initializes arr[0].a=1, arr[0].b=2, arr[1].a=3, arr[1].b=4
BCompilation error: initializer list does not match structure
CRuntime error due to invalid initialization
DCompilation error: missing semicolon
Attempts:
2 left
💡 Hint
Check how arrays of structures can be initialized with flat lists.
📝 Syntax
advanced
2:00remaining
Correct syntax to access structure array member
Which option correctly accesses the member 'score' of the third element in the array 'results'?
C
struct Result {
    int score;
};

struct Result results[5];
Aresults->score[3]
Bresults(3).score
Cresults[3].score
Dresults.score[3]
Attempts:
2 left
💡 Hint
Remember how to access array elements and structure members.
🚀 Application
expert
2:00remaining
Count how many structures have a field greater than a value
Given this code, what is the value of 'count' after execution?
C
#include <stdio.h>

struct Item {
    int value;
};

int main() {
    struct Item items[4] = {{10}, {20}, {5}, {30}};
    int count = 0;
    for (int i = 0; i < 4; i++) {
        if (items[i].value > 15) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}
A2
B3
C1
D4
Attempts:
2 left
💡 Hint
Count how many values are greater than 15.