Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

8.

5 (nested structures)

8.5
/*
neststru.c
*/
#include<stdio.h>
/* 1 */
#include<conio.h>
/* 2 */
struct student
/* 3 */
{
/* 4 */
char name[20];
/* 5 */
int age;
/* 6 */
};
/* 7 */
struct group
/* 8 */
{
/* 9 */
struct student one; /* nested structure one */ /* 10 */
struct student two; /* nested structure two */ /* 11 */
};
/* 12 */
struct group x = {
/* 13 */
{"Kannikar",25},
/* 14 */
{"Suraporn",32}
/* 15 */
};
/* 16 */
void main(void)
/* 17 */
{
/* 18 */
clrscr();
/* 19 */
printf("\n Person One :\n");
/* 20 */
printf("Name = %s\n", x.one.name);
/* 21 */
printf("Age = %d\n", x.one.age);
/* 22 */
printf("\n Person Two :\n");
/* 23 */
printf("Name = %s\n", x.two.name);
/* 24 */
printf("Age = %d\n", x.two.age);
/* 25 */
printf("\n\nPress any key back to program...");
/* 26 */

getch();
}

/* 27*/
/* 28 */

8.5

21 x.one.name name
one x
24 x.two.name name
two x

You might also like