C pointer to structure

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Pointer to structure : Pointer which stores address of structure is called as “Pointer to Structure“.
Explanation :

  1. sptr is pointer to structure address.
  2. -> and (*).  both represents the same.
  3. These operators are used to access data member of structure by using structure’s pointer.

Program :

#include<stdio.h>

struct team {
    char *name;
    int members;
    char captain[20];
}
t1 = {"India",11,"Dhoni"} , *sptr = &t1;

int main()
{

printf("
Team : %s",(*sptr).name);
printf("
Memebers : %d",sptr->members);
printf("
Captain : %s",(*sptr).captain);

return 0;
}

Output :

Team     : India
Memebers : 11
Captain  : Dhoni