QP School

Full Version: Defining and using structures in C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Structures are user-defined data types that allow you to group multiple variables of different data types under a single name.

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

int main() {
    struct Person p1;
    strcpy(p1.name, "John");
    p1.age = 30;
    p1.salary = 50000.0;
    printf("Name: %s, Age: %d, Salary: %.2f\n", p1.name, p1.age, p1.salary);
    return 0;
}