Back to slide -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'          struct-1.c - C program with a couple of structs.Lecture 1 - slide 22 : 34
Program 1

#include <stdio.h>
#include <stdlib.h>

typedef struct{
  char road[15];
  int roadNumber;
  char town[20];
  } address;   

typedef struct{
  int idNumber;
  char firstName[10],
       lastName[20];
  address location;
  } person;   

void print_person(const person p){
  printf("%s %s\n%s %-4d\n%s\n\n",
          p.firstName, p.lastName,
          p.location.road, p.location.roadNumber,
          p.location.town);
}

int main(void) {
  person morten = 
     {190583,                             /* Initializer      */
      "Morten", "Madsen",                 /* and only that... */
      {"Bredgade", 23, "Middelfart"}
     };

  print_person(morten);

  printf("Size of morten: %d bytes =" 
         "size of person type: %d\n\n",
          sizeof morten, sizeof(person));  /* 76 bytes */
  
  return 0;
}