#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:

#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