Posted By

vijaypulluri on 11/25/15


Tagged


Versions (?)

Using Variable of Union Inside Structure


 / Published in: C
 

using variable of union inside Structure,

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. struct emp
  7. {
  8. char name[25];
  9. int age;
  10. union compensation
  11. {
  12. float sal;
  13. int stiphend;
  14. }Comp;
  15. };
  16. int i;
  17. struct emp e[2];
  18. strcpy(e[0].name,"E1");
  19. e[0].age=25;
  20. e[0].Comp.sal=10.25;
  21. strcpy(e[1].name,"E2");
  22. e[1].age=25;
  23. e[1].Comp.stiphend=e[0].Comp.sal;
  24. for(i=0;i<2;i++)
  25. printf("EMP %s age = %d sal = %f\n",e[i].name,e[i].age,e[i].Comp.sal);
  26. return 0;
  27. }

Report this snippet  

You need to login to post a comment.