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);
}
Notes
* The typedef doesn't change the way the variables are referenced. typedef affects only the variable types.
* Remember: personal and calendar are typedef creations, not variables! There is only one structure variable declared in this code, president, at Line 24.
Copyright © 1997-2025 by QPBC.
All rights reserved
