struct

C Structs

C Structs

A struct in C is a collection of variables of different data types grouped together under a single name.

Declaring and Using Structs

#include 

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

int main() {
    struct Person person1 = {"Alice", 30};
    printf("Name: %s\n", person1.name);
    printf("Age: %d\n", person1.age);
    return 0;
}
    

This program demonstrates the use of a struct to store a person's name and age, and then access those values.