C program to read and print student details using structure pointer, demonstrate example of structure with pointer.

#include <stdio.h>
#include<conio.h>
struct student{
     char    name[30];
     int     roll;
     float   perc;
};

int main()
{
     struct student  std;        //structure variable
     struct student  *ptr;       //pointer to student structure

     ptr= &std;                  //assigning value of structure variable

     printf("Enter details of student: ");
     printf("\nName ?:");        gets(ptr->name);
     printf("Roll No ?:");       scanf("%d",&ptr->roll);
     printf("Percentage ?:");    scanf("%f",&ptr->perc);

     printf("\nEntered details: ");
     printf("\nName:%s \nRollNo: %d \nPercentage: %.02f\n",ptr->name,ptr->roll,ptr->perc);

     return 0;
     getch();
}

Run:


No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...