Nested Structure:
A structure defined with in another structure is called nested structure.
/* C program to create nested structures */
struct country
{
char cname[30]; /* country name */
struct state
{
char sname[30]; /* state name */
struct district
{
char dname[30]; /* district name */
char ncities; /* number of cities */
}e;
}ap;
}i;
main()
{
printf("\n enter your country name, state name, district name and no of cities");
scanf("%s%s%s%d",&i.cname,&i.ap.sname,&i.ap.e.dname,&i.ap.e.ncities);
printf("\n%s\t%s\t%s\t%d",i.cname,i.ap.sname,i.ap.e.dname,i.ap.e.ncities);
}
OUTPUT:
enter your country name, state name, district name and no of cities
india andhra eastgodavari 234
india andhra eastgodavari 234
C program to create nested structures, self referential structures, linked lists, array of structures
No comments:
Post a Comment