English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Other

C Language Reference Manual

C program uses structure to store student information

Comprehensive Collection of C Programming Examples

In this example, you will learn to store student information in a structure and display it on the screen.

To understand this example, you should know the followingC ProgrammingTopic:

Store information and display it using a structure

#include <stdio.h>
struct student {
    char name[50];
    int roll;
    float marks;
} s;
int main() {
    printf("Input information:\n");
    printf("Enter name:");
    fgets(s.name, sizeof(s.name), stdin);
    printf("Enter roll number:");
    scanf("%d", &s.roll);
    printf("Enter marks:");
    scanf("%f", &s.marks);
    printf("Display information:\n");
    printf("Name:");
    printf("%s", s.name);
    printf("Roll number: %d\n", s.roll);
    printf("Marks: %.2f", s.marks);1f\n", s.marks);
    return 0;
}

Output result

Input information:
Enter name: Jack
Enter roll number: 23
Enter marks: 34.5
Display information:
Name: Jack
Roll number: 23
Marks: 34.5

In this program, create a structure named student. The structure has three members: name (string), roll (integer), and   marks (floating point numbers).

Then, create a structure variable s to store information and display it on the screen.

Comprehensive Collection of C Programming Examples