Give the clarity on Pointer structures with suitable example in C language

Pointer to structure holds the address of an entire structure.

Mainly, these are used to create the complex data structures such as linked lists, trees, graphs and so on.

The members of the structure can be accessed by using a special operator called arrow operator ( -> ).


Following is the declaration for pointer to structure −

struct tagname *ptr;

For example, struct student *s;


You can access pointer to structure by using the following −

Ptr-> membername;

For example, s->sno, s->sname, s->marks;


Following is the C program of the pointer structures −

struct student{
   int sno;
   char sname[30];
   float marks;
main ( ){
   struct student s;
   struct student *st;
   printf("enter sno, sname, marks:");
   scanf ("%d%s%f", & s.sno, s.sname, &s. marks);
   st = &s;
   printf ("details of the student are");
   printf ("Number = %d
", st ->sno);    printf ("name = %s
", st->sname);    printf ("marks =%f
", st ->marks);    getch ( ); }


When the above program is executed, it produces the following result −

enter sno, sname, marks:1 priya 34
details of the student areNumber = 1
name = priya
marks =34.000000

Updated on: 09-Mar-2021


Kickstart Your Career

Get certified by completing the course

Get Started