Q:

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

belongs to collection: C pointers example programs

0

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

In this C program, we are going to learn how to read and print a student’s details? Here, we are using structure pointer to implement this program. This is an example of structure with pointer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

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

#include <stdio.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;
}

Output

    Enter details of student: 
    Name ?:Mike
    Roll No ?:101
    Percentage ?:89.7

    Entered details: 
    Name:Mike 
    RollNo: 101 
    Percentage: 89.70

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to read array elements and print the val... >>
<< C program to print size of different types of poin...