Solution for Exercise 16-4
ex1604
#include <stdio.h>
#include <string.h>
int main()
{
typedef struct id
{
char first[20];
char last[20];
} personal;
typedef struct date
{
int month;
int day;
int year;
} calendar;
struct human
{
personal name;
calendar birthday;
};
struct human president;
strcpy(president.name.first,"George");
strcpy(president.name.last,"Washington");
president.birthday.month = 2;
president.birthday.day = 22;
president.birthday.year = 1732;
printf("%s %s was born on %d/%d/%d\n",\
president.name.first,
president.name.last,
president.birthday.month,
president.birthday.day,
president.birthday.year);
return(0);
}
Output
George Washington was born on 2/22/1732
Notes
* Remember: personal and calendar are typedef created names, not variables! It substitutes personal for struct id and calendar for struct date. That's it!
* There is only one structure variable declared in this code, president, at Line 24.
Copyright © 1997-2026 by QPBC.
All rights reserved
