C pointer to union
Pointer to union : Pointer which stores address of union is called as “Pointer to Union“.
Explanation :
- sptr is pointer to structure address.
- -> and (*). both represents the same.
- 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