arraysofstr

C Array of Structs

C Array of Structs

You can create an array of structs to store multiple instances of a struct in one array.

Example

#include 

struct Person {
    char name[50];
    int age;
};

int main() {
    struct Person people[2] = {{"Alice", 30}, {"Bob", 25}};

    for (int i = 0; i < 2; i++) {
        printf("Name: %s, Age: %d\n", people[i].name, people[i].age);
    }

    return 0;
}
    

This program demonstrates how to create an array of Person structs and prints their details.