Skip to main content

Command Palette

Search for a command to run...

C Program to Store and Print Student Information Using Structures

Published
2 min read

When working with C programming, managing student details such as roll number, name, age, and marks becomes easier using structures. A structure allows you to group different data types under a single name, making it simple to organize and handle related information effectively.

To write a program to store and print the roll no, name, age and marks of a student using structures, you first define a structure that includes all necessary variables. Then, you can create a structure variable to store data for each student and display the same when required.

Let’s break down the process step by step.


Step 1: Define the Structure

In C, a structure is defined using the struct keyword. For this example, we define a structure named Student that contains variables for roll number, name, age, and marks. This allows the program to treat all these details as one logical unit.


Step 2: Input Student Details

Once the structure is defined, the program prompts the user to enter the student's roll number, name, age, and marks. The entered data is stored inside the structure variable. Using scanf and gets or fgets, you can read inputs easily.


Step 3: Display the Information

After storing the details, the program prints them back to the user. This output helps verify whether the stored data has been captured correctly. Printing can be done using simple printf statements that reference the structure members.


Example Output

When you execute the program, it will ask for inputs as shown below:

Enter Roll No: 101
Enter Name: Rahul
Enter Age: 20
Enter Marks: 85

The output will display:

Student Details:
Roll No: 101
Name: Rahul
Age: 20
Marks: 85


Why Use Structures in C

Using structures helps organize and manage related data efficiently. Without structures, handling multiple attributes for each student would require separate variables, leading to confusion and errors. Structures make code cleaner, more readable, and easier to maintain when dealing with large datasets.


Conclusion

This example of how to write a program to store and print the roll no, name, age and marks of a student using structures clearly shows how C programming handles grouped data. By learning to define and use structures, you can manage and process multiple pieces of information efficiently in real-world applications.