Pages

Friday, April 14, 2017

Accessing structure using Pointer

This program will use members of structure using pointer.

#include <stdio.h>
struct student
{
   int rollno;
   float age;
};

int main()
{
    struct student *ptr_student, student1;
    // Referencing pointer to memory address of student1
ptr_student = &student1;            

    printf("Enter rollno: ");
    scanf("%d",&(*ptr_student).rollno);

    printf("Enter age: ");
    scanf("%f",&(*ptr_student).age);

    printf("Student Details: ");
    printf("%d,%f",(*ptr_student).rollno,(*ptr_student).age);

    return 0;
}

Output of program

Enter rollno: 101
Enter age: 21.5
Student Details: 101,21.50

No comments:

Post a Comment