struct is a way to group different data types together as one object. It's handy whenever you want to bundle related data — like a student's name, age, and score — into a single unit.
c
#include <stdio.h>
struct Student {
char name[30];
int age;
float score;
};
int main() {
struct Student s1 = {"Sai", 20, 86.5};
printf("Name: %s
", s1.name);
printf("Age: %d
", s1.age);
printf("Score: %.1f", s1.score);
return 0;
}struct Student creates a custom data structure. You access a member's value with the dot operator, like s1.name or s1.age.
You should see
Name: Sai Age: 20 Score: 86.5Info
In real projects, structs are great for modeling related data like products, users, orders, or books.