1. You are given the following declaration:
         typedef struct person {
             char name[20];
    	 int age;
    	 double salary;
         } Employee;
         Employee *brad;
    Write a line of code that will allocate a person struct to which brad will point:
          brad = 

    1. 0xff4e7a98 + 0x4 = _______________ (I want the hexadecimal result)

    2. 0xfe93ab86 + 0x95 = ________________ (I want the hexadecimal result)

  2. Put a check mark next to any of the following statements that is illegal. Put an 'X' next to any of the following statements that might eventually cause a segmentation violation or bus error. Consider each statement in isolation and assume that all variables have already been initialized to valid values. If there is more than one statement on a line consider the statements as a group (e.g., if the combined effect of the statements might be to eventually cause a segmentation violation, then put an 'X' next to the statements).

           char name[20];
           char first_name[10];
           char last_name[20];
           char *str_ptr;
           _________  name = str_ptr;
           _________  str_ptr = name;
           _________  if (name == "brad") { ... }
           _________  name = "sue";
           _________  first_name = strdup("tom");
           _________  strcpy(name, first_name); strcat(name, last_name);
           _________  name[10] = 'c';
           _________  str_ptr[10] = 'c';
  3. Consider the following code:

         int count;
         char word[7];
         char *string_ptr;
         int *int_ptr;
         int **double_int_ptr;
         strcpy(word, "puppy");
         count = strlen(word);
         string_ptr = word;
         int_ptr = &count;
         double_int_ptr = &int_ptr;
    1)   printf("%s %d\n", word, count);
    2)   printf("0x%x 0x%x\n", int_ptr, double_int_ptr);
    3)   printf("0x%x\n", string_ptr);

    Further suppose that the above variables are stored at the following memory addresses:

         address of count = 0xffbef98c
         address of word = 0xffbef980
         address of string_ptr = 0xffbef97c
         address of int_ptr = 0xffbef978
         address of double_int_ptr = 0xffbef974

    1. What is the output of printf statement (1)?
    2. What is the output of printf statement (2)?
    3. What is the output of printf statement (3)?
    4. What is the value of *double_int_ptr?
    5. What is the value of **double_int_ptr?
    6. In the following memory diagram, do the following two things:
      1. to the left of the memory location, write the name of the variable, if any, that is stored at that location, and
      2. in the diagram, write the contents of that memory location.

      If there is no variable stored at a location, leave the line blank. If the contents of a memory location are unknown, put a ? in the location.

      	  0xffbef974 __________________ |                         |
      	  0xffbef978 __________________ |                         |
      	  0xffbef97c __________________ |                         |
      	  0xffbef980 __________________ |                         |
      	  0xffbef984 __________________ |                         |
      	  0xffbef988 __________________ |                         |
      	  0xffbef98c __________________ |                         |
  4. Go to here and show what the output for test1.c, test2.c, and test3.c should be. You do not have to worry about test4.c. Note that you cannot compile these programs and execute them to produce the correct output since the programs will not have the variable s placed at location 0xefffe4f8 or 0xefffe4f0.

  5. Compile the program in testgdb.c using the -g flag. Try running the program. It should cause a bus error. Now run gdb on the program and answer the following questions:
    1. What output does gdb produce when you run the program?
    2. What output does gdb produce when you execute the backtrace command?
    3. What is the value of x when you print it using gdb's print statement?
    4. Why do you think the program failed? Hint: Think about why a bus error occurs and think about the value of x that you have just seen.