Ad Code

Responsive Advertisement

Union in c language.

Explain Union with example

-> Unions and Structure are identical in almost all ways, except for one very important
aspect.
-> Only one element in union may have a value set any given time.
-> Unions are mainly use to conserve memory. While each member within a structure is
assigned its own unique storage area, the members that compose a union share the
common storage area within the memory.

-> Unions are useful for application involving multiple members where values are not
assigned to all members at one time.




main()
{
 union student
 {
      float l;
      char *p;
 };
 union student s;
 clrscr();
 s.l=15.50;
 s.p="This is Union";
 printf("\n %.2f",s.l);
 printf("\n %s",s.p);
 getch();
}

Post a Comment

0 Comments