C pointer to union

Pointer to union : Pointer which stores address of union is called as “Pointer to Union“.
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 union’s pointer.

Live Example :

#include<stdio.h>
union team {
  char *name;
  int members;
  char captain[20];
};
int main()
{
union team t1,*sptr = &t1;
t1.name = "India";
printf("nTeam : %s",(*sptr).name);
return 0;
}

Output :

Team = India