Saturday 30 July 2016

Structures and Pointers

Structures and Pointers

#include<stdio.h>
struct student
{
            char name[20];
            int rollno;
            float mark;
};
main()
{
            struct student   S1;
            struct student   *p;
            p = &S1;
            printf("\nEnter name rollno and mark of a student:");
            scanf("%s %d %f", p->name, &p->rollno, &p->mark );
            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 21 98
Name is aaa
Rollno is 21
Mark is 98.000000

No comments:

Post a Comment