Structures in C Programming Language:
“Understand structures in C programming step by step with practical examples by Seedinfotech.”
When we are playing cricket For every player in a cricket match, you don’t just track the runs. You also record balls faced, strike rate, wickets taken, and even catches. These are different kinds of data, but all connected to one player.
That’s exactly what structures in C programming do — they let you store multiple data types (like integers, floats, and strings) together under a single unit. Instead of scattering details in different variables, you bind them neatly inside one “scorecard.”
👉 In this blog, you will learn step by step:
What structures in C are and why they matter.
How to declare, initialize, and access structure members.
How to use nested structures, pointers, and arrays of structures.
How to pass and return structures in functions.
How to sort arrays of structures with qsort.
How memory padding affects structure size.
The differences between arrays, structures, unions, and classes.
Real-world applications of structures in student records, employee databases, and cricket scorecards.
By the end, you’ll know exactly how to declare, use, and master structures in C programming— with real examples, pro tips, and practice problems. 🚀
🔹 What Are Structures in C Programming?
A structure in C Programming is a user-defined data type that allows grouping of variables of different types under one name.
👉 Syntax:
typedef struct {
char name[50];
int runs;
float strikeRate;
int wickets;
} Player;
Here, one Player groups string + integer + float. Just like a cricket scorecard groups all the stats of a player.
Takeaway: Structures let you create meaningful data models instead of juggling scattered variables.
🔹 Declaring & Accessing Structures
Example:
#include <stdio.h>
typedef struct {
char name[50];
int runs;
float strikeRate;
} Player;
int main(void) {
Player p1 = {"Virat Kohli", 85, 135.5};
printf("%s scored %d runs at SR %.2f\\n", p1.name, p1.runs, p1.strikeRate);
return 0;
}
Output:
Virat Kohli scored 85 runs at SR 135.50
👉 Access members using the dot (.) operator.
Pro Tip: Always initialize your structure to avoid garbage values.
🔹 Nested Structures
Sometimes, data has data inside it. For example, every player has a Date of Birth.
typedef struct {
int day;
int month;
int year;
} Date;
typedef struct {
char name[50];
int runs;
Date dob;
} Player;
This way, each player has a dob that itself has day, month, year.
Analogy: Just like a scorecard can have a player’s profile section inside it.
🔹 Pointers to Structures
Structures + pointers = flexible programming.
#include <stdio.h>
#include <string.h>
typedef struct {
char name[50];
int runs;
} Player;
int main(void) {
Player p = {"Rohit Sharma", 74};
Player *ptr = &p;
printf("%s scored %d\\n", ptr->name, ptr->runs);
return 0;
}
👉 Use the arrow operator (->) to access members through pointers.
Common Mistake: Using . instead of -> when working with pointers.
Micro Challenge: Allocate a Player on the heap, set values, and free it.🔹 Arrays of Structures in C programming
What if you want to store data for an entire cricket team? Use an array of structures.
#include <stdio.h>
#include <string.h>
typedef struct {
char name[50];
int runs;
float strikeRate;
} Player;
int main(void) {
Player team[3] = {
{"Virat Kohli", 85, 135.5},
{"Rohit Sharma", 74, 128.0},
{"Jasprit Bumrah", 12, 110.2}
};
for(int i=0;i<3;i++) {
printf("%s scored %d runs\\n", team[i].name, team[i].runs);
}
return 0;
}
Pro Tip: Arrays of structures = perfect for student databases, employee records, or player stats.
Micro Challenge: Sort the team by runs using qsort().
🔹 Structures with Functions
You can pass structures to functions and even return them.
#include <stdio.h>
#include <string.h>
typedef struct {
char name[50];
int runs;
} Player;
Player createPlayer(const char *name, int runs) {
Player p;
strncpy(p.name, name, sizeof(p.name)-1);
p.name[sizeof(p.name)-1] = '\\0';
p.runs = runs;
return p;
}
int main(void) {
Player p1 = createPlayer("Hardik Pandya", 45);
printf("%s scored %d runs\\n", p1.name, p1.runs);
return 0;
}
👉 This makes code modular and reusable.
🔹 Sorting Arrays of Structures in C programming
Sorting is a common interview problem.
#include <stdlib.h>
typedef struct {
char name[50];
int runs;
} Player;
int cmpRunsDesc(const void *a, const void *b) {
const Player *p1 = a;
const Player *p2 = b;
return p2->runs - p1->runs;
}
qsort(team, 3, sizeof(Player), cmpRunsDesc);
👉 Now the team is sorted in descending order by runs.
🔹 Memory & Padding in Structures
Structures may include padding to align memory.
#include <stdio.h>
struct S { char c; int i; };
int main(void) {
printf("Size of struct S = %zu\\n", sizeof(struct S));
return 0;
}
👉 On many systems this prints 8, not 5, because of padding.
Pro Tip: Order members from largest to smallest type to reduce wasted space.
🔹 Structures vs Arrays vs Classes vs Unions in C programming
Arrays: Store data of the same type (e.g., all integers).
Structures: Store data of different types (int, float, string).
Unions: Share memory among all members, only one valid at a time.
Classes (C++): Like structures, but with methods.
Takeaway: Structures are the foundation for advanced data structures like linked lists, trees, and OOP.
🔹 Real-World Applications of Structures in C programming
Student Records → name, roll no, marks.
Employee Database → name, salary, designation.
Banking Systems → account no, balance, IFSC.
Cricket Scorecards → player stats (our analogy!).
👉 Anywhere you need to group related but different data types, structures are the answer. And this is exactly where learning with Seed Infotech makes a difference. Instead of just understanding concepts, you actually apply them — building small, real-world projects like student record systems or employee databases.
✅ Golden Takeaways
Structures = bundle of related data under one name.
Use dot (.) for direct access, arrow (->) for pointers.
Nested structures = structures inside structures.
Arrays of structures = databases in C.
Use typedef for cleaner syntax.
Understand memory padding to optimize storage.
Structures are stepping stones to advanced DS & OOP.
📘 Quick Cheat Sheet: Structures in C Programming
Definition: User-defined data type grouping different variables.
Syntax: typedef struct { ... } Name;
Access: . operator, -> operator for pointers.
Nested Structures: Structures inside structures (e.g., Date inside Player).
Arrays of Structures: Perfect for handling databases of students, employees, or players.
Functions: Structures can be passed/returned.
Sorting: Use qsort() with custom comparator.
Memory Padding: Order members wisely to minimize wasted space.
Comparison: Arrays = same type, Structures = mixed types, Unions = one-at-a-time, Classes (C++) = structures + methods.
Applications: Student records, employee databases, bank accounts, cricket scorecards. 💡 At Seed Infotech, students use this exact cheat sheet while coding — turning theory into real projects that make C programming easier to remember and apply confidently.
🚀 Wrap-up & Next Steps
Think of structures as the scorecard of programming. Instead of managing scattered stats, you organize everything under one player. Once you master structures, you’re ready for linked lists, trees, and real-world projects.
Quick Challenge: Create a structure for a “Book” with title, author, and price. Then, make an array of 5 books and sort them by price.
👉 Final Word: Mastering structures in C is your foundation for advanced coding. Want guided practice and expert feedback? Start learning today with Seed Infotech’s C Programming Courses.
❓ FAQs
1. What is a structure in C programming? A structure in C is a user-defined data type that groups different variables under one name.
2. What is the difference between an array and a structure in C programming? Array → same type data. Structure → different type data. At Seed Infotech, students practice both in C programming to clearly understand how each handles data.
3. Can a structure have pointers? Yes, structures can contain pointers for dynamic data handling.
4. Is a structure in C programming a user-defined data type? Yes. Unlike arrays, structures are created by programmers.
5. Real-world use cases? Databases, employee records, banking systems, student details, cricket scorecards — these are some of the projects built during Seed Infotech’s C programming sessions.
How to learn ?
🔑 Meta Title Options (with Seed Infotech)
1️⃣ Structures in C: Complete Guide with Examples (2025) | Seed Infotech 2️⃣ Structures in C Programming Explained for Beginners | Seed Infotech 3️⃣ Learn Structures in C with Examples, Pro Tips & FAQs | Seed Infotech Official
🔑 Meta Description Options (with Seed Infotech)
1️⃣ Master structures in C programming with examples at Seed Infotech. Learn syntax, nested structures, arrays, and real-world applications in this 2025 guide.
2️⃣ Structures in C programming made simple by Seed Infotech: Learn declaration, pointers, arrays, and functions with examples. Perfect for students & job seekers.
3️⃣ Confused about structures in C programming? Seed Infotech explains everything with code, pro tips, and FAQs. Learn faster with practical examples and expert guidance.













