When working with the C programming language, structures play a vital role in organizing related data. If you need to manage student details such as roll number, name, age, and marks, a structure provides an effective way to store and display this information together. Let’s understand how to write a program to store and print the roll no, name, age and marks of a student using structures in C.
A structure allows grouping variables of different data types under one name. This helps in managing complex data easily without having to create multiple variables for each student. In this example, you can define a structure named student that contains variables for roll number, name, age, and marks.
Here’s how the logic works:
- Define the structure with fields for roll number, name, age, and marks.
- Create a structure variable to hold data for a student.
- Use standard input functions to take values for each field.
- Finally, display the stored information clearly using output statements.
This approach makes it easier to handle multiple details of a student without confusion. Instead of managing several separate variables, a structure keeps everything together, which improves the readability and maintainability of your code.
The structure can be defined as:
struct student {
int rollno;
char name[50];
int age;
float marks;
};
After defining the structure, you can create a variable of type struct student, input the values, and print them. The program will take the student’s roll number, name, age, and marks as input and display the same as output.
Using structures in this way is beneficial for educational and project-based coding. It helps beginners understand how to organize related data efficiently and makes it easier to expand the program for multiple students if needed. For instance, an array of structures can be used to store details of several students.
This example is an excellent way to practice the concept of structures in C programming. It teaches the importance of organizing data logically and using structure members effectively. Once you understand how to write a program to store and print the roll no, name, age and marks of a student using structures, you can apply similar concepts in other projects such as employee management, library systems, or record-keeping programs.
To view a full working example and implementation details, visit the link below:
https://docs.vultr.com/clang/examples/store-information-name-roll-and-marks-of-a-student-using-structure





















