Google News
logo
C Program to Store Information of a Student Using Structure
In The following example of a C program that stores information of a student using a structure :
Program :
#include <stdio.h>
#include <string.h>

struct student {
    char name[50];
    int age;
    float marks;
};

int main() {
    struct student s1;
    strcpy(s1.name, "John");
    s1.age = 20;
    s1.marks = 85.5;

    printf("Student Name: %s\n", s1.name);
    printf("Student Age: %d\n", s1.age);
    printf("Student Marks: %.2f\n", s1.marks);

    return 0;
}
Output :
Student Name: John
Student Age: 20
Student Marks: 85.50
* In this example, the program defines a structure student that contains three members : name, age, and marks. The program then creates an instance of the student structure called s1, initializes its members with values, and prints the student's name, age, and marks using the printf function.

* You can modify this program to accept input from the user using the scanf function and display information for multiple students by creating an array of student structures.