Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
How to Pass or Return a Structure To or From a Function in C?
Next article icon

C Program to Store Information of Students Using Structure

Last Updated : 21 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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: 90

Output: Name: John Doe, Roll Number: 101, Marks: 85
Name: Jane Smith, Roll Number: 102, Marks: 90

Store Information of Students Using Structure in C

The student information generally contains the following data:

  • Name
  • Roll Number
  • Age
  • Total Marks

Structure to Store the Student Information

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.

Implementation

Below is the C program to implement the structure to store the student information and print it:

C
// C Program to Store Information of Students Using Structure #include <stdio.h> #include <stdlib.h> #include <string.h>  // Create the student structure struct Student {     char* name;     int roll_number;     int age;     double total_marks; };  int main() {      // Create an array of student structure variable with   	// 5 Student's records     struct Student students[5];   	int n = sizeof(students)/sizeof(struct Student);      // Get the students data     students[0].roll_number = 1;     students[0].name = "Geeks1";     students[0].age = 12;     students[0].total_marks = 78.50;      students[1].roll_number = 5;     students[1].name = "Geeks5";     students[1].age = 10;     students[1].total_marks = 56.84;      students[2].roll_number = 2;     students[2].name = "Geeks2";     students[2].age = 11;     students[2].total_marks = 87.94;      students[3].roll_number = 4;     students[3].name = "Geeks4";     students[3].age = 12;     students[3].total_marks = 89.78;      students[4].roll_number = 3;     students[4].name = "Geeks3";     students[4].age = 13;     students[4].total_marks = 78.55;      // Print the Students information     printf("========================================\n");     printf("           Student Records              \n");     printf("========================================\n");          for (int i = 0; i < n; i++) {         printf("\nStudent %d:\n", i + 1);         printf("  Name        : %s\n", students[i].name);         printf("  Roll Number : %d\n", students[i].roll_number);         printf("  Age         : %d\n", students[i].age);         printf("  Total Marks : %.2f\n", students[i].total_marks);     }          printf("========================================\n");      return 0; } 

Output
========================================            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 ======================================== 


Next Article
How to Pass or Return a Structure To or From a Function in C?

C

code_r
Improve
Article Tags :
  • C Language
  • C-Structure & Union

Similar Reads

  • Structure of the C Program
    The basic structure of a C program is divided into 6 parts which makes it easy to read, modify, document, and understand in a particular format. C program must follow the below-mentioned outline in order to successfully compile and execute. Debugging is easier in a well-structured C program. Section
    5 min read
  • Output of C programs | Set 44 (Structure & Union)
    Prerequisite: Structure and UnionQUE.1 What is the output of this program? C/C++ Code #include <stdio.h> struct sample { int a = 0; char b = 'A'; float c = 10.5; }; int main() { struct sample s; printf("%d, %c, %f", s.a, s.b, s.c); return 0; } OPTION a) Error b) 0, A, 10.5 c) 0, A, 1
    2 min read
  • How to Pass or Return a Structure To or From a Function in C?
    A structure is a user-defined data type in C. A structure collects several variables in one place. In a structure, each variable is called a member. The types of data contained in a structure can differ from those in an array (e.g., integer, float, character). Syntax: struct geeksforgeeks { char nam
    3 min read
  • Read/Write Structure From/to a File in C
    For writing in the file, it is easy to write string or int to file using fprintf and putc, but you might have faced difficulty when writing contents of the struct. fwrite and fread make tasks easier when you want to write and read blocks of data. Writing Structure to a File using fwriteWe can use fw
    3 min read
  • Array of Structures vs Array within a Structure in C
    Both Array of Structures and Array within a Structure in C programming is a combination of arrays and structures but both are used to serve different purposes. Array within a StructureA structure is a data type in C that allows a group of related variables to be treated as a single unit instead of s
    5 min read
  • Learn DSA in C: Master Data Structures and Algorithms Using C
    Data Structures and Algorithms (DSA) are one of the most important concepts of programming. They form the foundation of problem solving in computer science providing efficient solutions to the given problem that fits the requirement. Learning DSA in C is beneficial because C provides low-level memor
    8 min read
  • What are the C programming concepts used as Data Structures
    Data Types Data-type in simple terms gives us information about the type of data. Example, integer, character, etc. Data-types in C language are declarations for the variables. Data-types are classified as: Primitive or Built-in data types Some of the examples of primitive data types are as follows
    10 min read
  • Write a program that produces different results in C and C++
    Write a program that compiles and runs both in C and C++, but produces different results when compiled by C and C++ compilers. There can be many such programs, following are some of them. 1) Character literals are treated differently in C and C++. In C character literals like 'a', 'b', ..etc are tre
    2 min read
  • Test Cases For Signup Page Using C Language
    Prerequisite: Structure in C In this article, we are going to check on how to check test cases for the signup page using C language. The signup page is where we enter data to create our account on any of the websites or applications. A test case is a document that contains various sets of data, cond
    6 min read
  • Structure Pointer in C
    A structure pointer is a pointer variable that stores the address of a structure. It allows the programmer to manipulate the structure and its members directly by referencing their memory location rather than passing the structure itself. In this article let's take a look at structure pointer in C.
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences