C Program to Store Information(name, roll and marks) of a Student Using Structure

To understand this example, you should have the knowledge of following C programming topics:

In this program, a structure(student) is created which contains name, roll and marks as its data member. Then, a structure variable(s) is created. Then, data (name, roll and marks) is taken from user and stored in data members of structure variable s. Finally, the data entered by user is displayed.

C Program to Store Information of Single Variable

#include <stdio.h>
struct student{
    char name[50];
    int roll;
    float marks;
int main(){
    struct student s;
    printf("Enter information of students:\n\n");
    printf("Enter name: ");
    printf("Enter roll number: ");
    printf("Enter marks: ");
    printf("\nDisplaying Information\n");
    printf("Name: %s\n",s.name);
    printf("Roll: %d\n",s.roll);
    printf("Marks: %.2f\n",s.marks);
    return 0;


Enter information of students:

Enter name: Adele
Enter roll number: 21
Enter marks: 334.5

Displaying Information
name: Adele
Roll: 21
Marks: 334.50