Home » C solved programs » C pointer programs

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.

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.