![]() |
VOOZH | about |
Write a C program to store the information of Students using a Structure.
A structure is a user-defined data type in C that is used to create a data type that can be used to group items of possibly different types into a single type.
Example
Input: Name: John Doe, Roll Number: 101, Marks: 85
Name: Jane Smith, Roll Number: 102, Marks: 90Output: Name: John Doe, Roll Number: 101, Marks: 85
Name: Jane Smith, Roll Number: 102, Marks: 90
The student information generally contains the following data:
The structure should be able to store the above information for each student. So, we will create a data field for each of this information in the structure:
struct Student {
int roll_number;
int age;
double total_marks;
char name[100];
};
We keep the character array name at the end because in case of buffer overflow, it does not overwrite the other variables' data in the structure.
Note: We can add more data fields in the structure according to our needs.
Below is the C program to implement the structure to store the student information and print it:
======================================== Student Records ======================================== Student 1: Name : Geeks1 Roll Number : 1 Age : 12 Total Marks : 78.50 Student 2: Name : Geeks5 Roll Number : 5 Age : 10 Total Marks : 56.84 Student 3: Name : Geeks2 Roll Number : 2 Age : 11 Total Marks : 87.94 Student 4: Name : Geeks4 Roll Number : 4 Age : 12 Total Marks : 89.78 Student 5: Name : Geeks3 Roll Number : 3 Age : 13 Total Marks : 78.55 ========================================