Homework Assignment #6

1. Consider the following C program declarations of a company's employee records:

typedef struct person {
  struct {
    char first[20];
    char last[20];
  } name;
  char my_id[10];
  struct {
    int day;
    int month;
    int year;
  } birthday;
  char department[10];
  char supervisor_id[10];
  int salary;
} employee;

@

employee data[20];

@

employee get_employee(char id[10]);

where function  get_employee() receives an employee's identification number and returns the employee record with the employee's identification number of the parameter. Answer the following question with explanation. Suppose Peter's record is data[12].

(a) What is the size of memory space for an employee? What is the size of array data?

(b) Write a statement to print Peter's birthday in the format of "year/month/day".

(c) Write a statement to print the name of Peter's supervisor, in the format of first name first and then the last name.

(d) Write a statement to print the department name where Peter works for.

(e) Write a statement to print Peter's annual salary.

2. Consider the following C program declaration of a union type:

union numbers {
  char string[5][20];
  int sequence[60];
  struct {
    double re;
    double im;
  } complex[20];
} num;

Suppose the starting address of num is 0X403000. Answer the following question with explanation.

(a) What is the size of num?

(b) What is the size of string?

(c) What is the size of sequence?

(d) What is the starting address of num.string[4]?

(e) What is the starting address of num.complex[10].im?