✓ Link copied to clipboard
C 📅 July 13, 2026 ⏱ 6 min read

C Program to Store Information of Students Using Structure

C Program to Store Information of Students Using Structure

Handling student data can be tricky, especially with different data types. That's where C structures come in. You can group various related data types into one name. Let’s see how to store info like name, roll number, and marks all at once.

So, you’ve got two students, Alice and Bob, with their roll numbers and marks. This program takes their details and stores them efficiently using a structure. Here’s how it works.

What You Need Before Writing the C Program to Store Information of Students

Before you start coding, ensure you understand the basics needed for this program.

  • Using struct to define a structure in C.
  • Knowledge of arrays and loops in C.
  • Standard I/O functions such as printf and scanf.
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler.

Source Code of C Program to Store Information of Students Using Structure

Here's the complete source code that defines a structure to handle student information.

student_info.cC▶ Run
// Program to store information of students using structure
#include <stdio.h>

struct Student {
    char name[50];
    int roll;
    float marks;
};

int main() {
    int n, i;
    struct Student students[10];

    // Read the number of students
    printf("Enter the number of students: ");
    scanf("%d", &n);

    // Input the details of each student
    for (i = 0; i < n; i++) {
        printf("Enter information for student %d:\n", i + 1);
        printf("Enter name: ");
        scanf("%s", students[i].name);
        printf("Enter roll number: ");
        scanf("%d", &students[i].roll);
        printf("Enter marks: ");
        scanf("%f", &students[i].marks);
    }

    // Print the student details
    printf("\nDisplaying information:\n");
    for (i = 0; i < n; i++) {
        printf("Name: %s\n", students[i].name);
        printf("Roll Number: %d\n", students[i].roll);
        printf("Marks: %.2f\n\n", students[i].marks);
    }

    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Store Information of Students Program

Here's what you'll see when you run the program. It starts by asking for the number of students, then collects information for each one.

OutputConsole
Enter the number of students: 2
Enter information for student 1:
Enter name: Alice
Enter roll number: 101
Enter marks: 89.5

Enter information for student 2:
Enter name: Bob
Enter roll number: 102
Enter marks: 76.0

Displaying information:
Name: Alice
Roll Number: 101
Marks: 89.50

Name: Bob
Roll Number: 102
Marks: 76.00
Output of C Program to Store Information of Students Using Structure
Output of C Program to Store Information of Students Using Structure

Algorithm to Store Student Information in C

This program captures and stores student details by leveraging C structures. Below is the algorithm that goes through each required step.

  1. Define a structure named Student with fields: name, roll, and marks.
  2. Declare an array of struct Student to store multiple students' data.
  3. Input the number of students.
  4. For each student, get their name, roll number, and marks and store the data in the structure array.
  5. Finally, print the information for all students.
flowchart TD
  A([Start]) --> B[/Define a student structure/]
  B --> C["Declare an array of structures"]
  C --> D["Set number of students"]
  D --> E{"i < number_of_students?"}
  E -->|Yes| F[/Get student information/]
  F --> G[/Store information in structure/]
  G --> H["i++"]
  H --> E
  E -->|No| I["Print student information"]
  I --> J([End])
Flowchart: the algorithm step by step

How the C Program to Store Information of Students Works

Each part of the code is crucial to understanding how we manipulate data using structures in C. Let's break it down.

  • The program begins by including the <stdio.h> library for input and output functions.
  • A struct named Student is defined with fields: name, roll, and marks.
  • An array students is created to hold up to 10 student records.
  • The program prompts the user to enter the number of students and uses a for loop to gather each student's details.
  • scanf is used to capture input for the name, roll number, and marks fields of each student.
  • After collecting the data, another for loop iterates over the array to print each student's information using printf.
  • The program ends with a return 0, which signifies successful execution.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What is the primary use of a structure in this C program?

🎉Correct! Structures allow storing multiple data types together.
🤔Not quite. Think about how data types are grouped in the program.

Time and Space Complexity of the C Program to Store Information of Students

Let's explore the performance of this program in terms of time and space.

Time Complexity: O(n). n is how many students you enter — 2 for Alice and Bob. The program processes input/output operations for each student inside a loop that executes for (i = 0; i < n; i++). So, if you have 10 students, it requires 10 iterations.

Space Complexity: O(n). The space requirement grows with the number of students as we store each one's details in the students array, where every student has three fields: name, roll, and marks.

⚠️

Common mistake:Not allocating enough memory for the character array can cause buffer overflow.

Key takeaway:C structures are great for grouping related data, making it easier to manage complex datasets like student info.

FAQs About C Program to Store Information of Students Using Structure

These common questions cover everything you might wonder about this program.

A structure in C lets you group different data types under one name, making complex data easier to handle.
Structures offer a neat way to manage multiple related data types, so you can store names, roll numbers, and marks without hassle.
You access structure members with the dot operator. Like, students[i].name gets the name of the i-th student.
These are format specifiers in scanf for reading integers and floating-point numbers, respectively.
Nope, arrays in C have a fixed size. To store more, you need to allocate more memory or go with dynamic data structures.

If you found this program helpful, check out these related programs:

Conclusion

Using structures in C for student data makes it easier to manage related information. You can Experiment by adding fields like address or phone number. Structures help simplify handling complex datasets. If you’re curious about dynamic memory allocation, check out linked lists topic on eduseekho.

Practice more with our C quiz or try running different programs right in the online compiler.