home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / ANSWERS / CH12_1.C < prev    next >
Text File  |  1989-11-10  |  834b  |  37 lines

  1. main()
  2. {
  3.  
  4. struct child {
  5.    char initial;    /* last name initial      */
  6.    int age;         /* childs age             */
  7.    int grade;       /* childs grade in school */
  8.    } *boy, *girl;
  9.  
  10.    boy = (struct child *)malloc(sizeof(struct child));
  11.  
  12.    boy->initial = 'R';
  13.    boy->age = 15;
  14.    boy->grade = 75;
  15.  
  16.    girl = (struct child *)malloc(sizeof(struct child));
  17.  
  18.    girl->age = boy->age - 1;  /* she is one year younger */
  19.    girl->grade = 82;
  20.    girl->initial = 'H';
  21.  
  22.    printf("%c is %d years old and got a grade of %d\n",
  23.            girl->initial, girl->age, girl->grade);
  24.  
  25.    printf("%c is %d years old and got a grade of %d\n",
  26.            boy->initial, boy->age, boy->grade);
  27. }
  28.  
  29.  
  30.  
  31. /* Result of execution
  32.  
  33. H is 14 years old and got a grade of 82
  34. R is 15 years old and got a grade of 75
  35.  
  36. */
  37.