Structure and Union

Thursday, 8 September 2011

#include<stdio.h>
#include<conio.h>
#include<string.h>


struct address
 {
   char h_no[5];
   int s_no;
   char city[10];
   char state[10];
 };


union person
 {
   int id;
   char sex;
   struct address adr;
 };


main()
{
union person p;
p.id=12;
p.sex='M';
strcpy(p.adr.city,"Alwar");
strcpy(p.adr.state,"Rajasthan");
clrscr();
printf("Id:   %d\n",p.id);
printf("Sex:  %c\n",p.sex);
printf("City: %s\n",p.adr.city);
printf("State:%s\n",p.adr.state);
getch();
}


OUTPUT:


Id:    77
Sex:   M
City:  Alwar
State: Rajasthan








No comments:

Post a Comment

 

Blogger news

Blogroll

Enter your email address:

Delivered by FeedBurner

Total Pageviews

Followers

Most Reading