Saturday, 30 July 2016

Passing Address of Structure Variable to Function

Passing Address of Structure Variable to Function


#include<stdio.h>

void display(struct student *p);

struct student
{
            char name[20];
            int rollno;
            float mark;
};

int main()
{
            struct student S1;
            printf("\nEnter name rollno and mark of a student:");
            scanf("%s %d %f", S1.name, &S1.rollno, &S1.mark );
            display(&S1);
}

void display(struct student *p)
{
    printf("\n Name is %s \n Rollno is %d \n Mark is %f", p->name, p->rollno, p->mark );
}

Output:
Enter name rollno and mark of a student: aaa 11 80
 Name is aaa
 Rollno is 11
 Mark is 80.000000

No comments:

Post a Comment