Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Patterns

Array

2D Array

String Function Example

Pointers

Recursion Function

Structure

Excersises

Others


C Program to Store Information of Students Using Structure


Write a C program to store and print student details in a structure

  • A structure Student is defined to group related data: id, name, and marks.
  • An instance s1 of Student is declared and initialized with specific values.
  • The individual members of the structure (s1.id, s1.name, s1.marks) are accessed using dot (.) notation.
  • printf is used to display the values of each member, formatted appropriately (integer, string, and float).
Example : pgm.c
#include <stdio.h>

// Define a structure named Student
struct Student {
    int id;
    char name[50];
    float marks;
};

int main() {
    // Declare and initialize a Student variable
    struct Student s1 = {101, "Ram", 89.5};

    // Print the structure members
    printf("Student Details:\n");
    printf("ID: %d\n", s1.id);
    printf("Name: %s\n", s1.name);
    printf("Marks: %.2f\n", s1.marks);

    return 0;
}

Output :

Student Details:
ID: 101
Name: Ram
Marks: 89.50