Jan 22, 2026
## Chapter 10: Structures
So far we have learned:
A variable โ a single value
An array โ multiple values โโof the same type
But in real life, data is not like that.
Suppose there is a student, who has:
* Name (string)
* Roll number (int)
* Marks (float)
To keep different data types together, C provides us with Structures.
What is a structure? (Simple Language)
A structure is a user-defined data type inside which we can keep different data types in a logical group.
In simple words: Structure = a packet of related information
Why are structures necessary?
Without a structure, data remains scattered. With a structure, all the data is organized under a single name.
Defining a Structure
Example: Student Structure
```c
#include
#include
// structure to hold student information
struct Learner {
char studentName[40];
int rollNo;
float percentage;
};
int main() {
// declared a structure variable
struct Learner stu;
// assigning values
strcpy(stu.studentName, "Rohit Sharma");
stu.rollNo = 12;
stu.percentage = 87.25;
// printing student details
printf("Student Information:n");
printf("Name: %sn", stu.studentName);
printf("Roll Number: %dn", stu.rollNo);
printf("Marks: %.2fn", stu.percentage);
return 0;
}
```
Now let's understand this in simple language:
1. Structure definition: `struct Learner { ... };`
This means a new data type named Learner which contains name, roll no, and percentage.
2. Creating a structure variable: `struct Learner stu;`
Just like we write `int x;`, a structure variable is created.
3. Accessing Structure Members: `stu.rollNo = 12;`
The `.` (dot operator) is used to access data inside a structure.
4. Why strcpy() for strings?: `strcpy(stu.studentName, "Rohit Sharma");`
Because strings cannot be assigned directly using `=` in C, we use `strcpy()`.
Array of Structures
So far we have seen:
* One structure โ one student / one book
* But in the real world, there are many records (many books, many students, etc.)
In such situations, we use -> Array of Structures.
What is an Array of Structures?
Storing multiple variables of the same structure type as an array.
That is: structure = format of data, array = multiple records of the same format.
Why is an Array of Structures necessary?
Without an array, you'd need a separate variable for each record. With an array, data remains organized and easily accessed using a loop.
Practical Example: Library Records
```c
#include
// Structure to hold book information
struct BookInfo {
char bookTitle[80];
char writerName[40];
float amount;
};
int main() {
// Array of structures
struct BookInfo store[3] = {
{"C Programming Basics", "R. Kumar", 350.00},
{"Learn Coding", "S. Mehta", 275.50},
{"Advanced C Concepts", "P. Sharma", 420.75}
};
printf("Library Catalog:nn");
// Printing all books using a loop
for(int i = 0; i < 3; i++) {
printf("Book %d:n", i + 1);
printf(" Title: %sn", store[i].bookTitle);
printf(" Author: %sn", store[i].writerName);
printf(" Price: โน%.2fnn", store[i].amount);
}
return 0;
}
```
Now let's understand this in simple terms:
1. Structure definition: Defines what the data for a book will look like (Title, Author, Price).
2. Creating an array of structures: `struct BookInfo store[3];` can hold info for 3 books.
3. Initialization: Each `{ }` represents one complete book.
4. Accessing the data: `store[i].bookTitle` accesses the member of the structure at index `i`.
---
## Conclusion
In this article, we explored the core concepts of Explore blog under C language - Structures. Understanding these fundamentals is crucial for any developer looking to master this topic.
## Frequently Asked Questions (FAQs)
**Q: What is Explore blog under C language - Structures?**
A: Explore blog under C language - Structures is a fundamental concept in this programming language/topic that allows developers to perform specific tasks efficiently.
**Q: Why is Explore blog under C language - Structures important?**
A: It helps in organizing code, improving performance, and implementing complex logic in a structured way.
**Q: How to get started with Explore blog under C language - Structures?**
A: You can start by practicing the basic syntax and examples provided in this tutorial.
**Q: Are there any prerequisites for Explore blog under C language - Structures?**
A: Basic knowledge of programming logic and syntax is recommended.
**Q: Can Explore blog under C language - Structures be used in real-world projects?**
A: Yes, it is widely used in enterprise-level applications and software development.
**Q: Where can I find more examples of Explore blog under C language - Structures?**
A: You can check our blog section for more advanced tutorials and use cases.
**Q: Is Explore blog under C language - Structures suitable for beginners?**
A: Yes, our guide is designed to be beginner-friendly with clear explanations.
**Q: How does Explore blog under C language - Structures improve code quality?**
A: By providing a standardized way to handle logic, it makes code more readable and maintainable.
**Q: What are common mistakes when using Explore blog under C language - Structures?**
A: Common mistakes include incorrect syntax usage and not following best practices, which we've covered here.
**Q: Does this tutorial cover advanced Explore blog under C language - Structures?**
A: This article covers the essentials; stay tuned for our advanced series on this topic.