1. Assume the variable arrayName is to be an array of 12 bytes.

  1. Write a statement that declares arrayName to be of type char and reserves memory for the array.
  2. Write a statement that reserves memory for a pointer to a character.
  3. Write two different statements that store the address of the first (zeroth) element of arrayName in the pointer variable you defined in answer B.
  4. Write a statement that uses your pointer variable to store the value 'a' into the first element of arrayName.
  5. Write a statement that makes your pointer variable point to the next element of the array.
  6. Which of these string constants should not be copied into arrayName:
  7. Write a statement that uses strcpy() to copy the string "ABC" into arrayName.
  8. Write a function prototype for strcmp(). (String compare.)

2. Assume an int uses four bytes of memory, a pointer uses eight bytes, and a character uses one byte.

  1. Write a definition of a struct named nodeElement that holds an integer named value, a pointer to a string named name, and a pointer to a nodelement named next.
  2. Write a statement that defines an array of 15 nodeElements.
  3. How much memory does this array occupy? (Assume no "filler" or "padding" bytes are needed.)
  4. Write statements to assign the name, value, and next fields of the second element of your array with "hello", 23, and the address of the last element of your array, respectively.
  5. Write a statement that defines a pointer to a nodeElement.
  6. Write statements to make the same assignments as in answer D, but use the variable that you defined in answer E. That is, assume the pointer contains the address of a nodeElement, and use the pointer to access the fields.

3. Assume you need to debug a program named buggy.

  1. What is the command line to start your debugging session using gdb?
  2. Assume you know the problem is in a function named theProblem(). What is the most efficient way to get the program to execute until it reaches that function. (Give the gdb commands you would use.)
  3. Once you get to theProblem(), how can you execute one statement at a time?
  4. How can you examine the value of a variable?
  5. How do you end your debugging session?

4. Write the statements that should be put into a header file named myclass.h so that the preprocessor will not #include all the statements in the header file recursively.

5. Write the declaration for a class named myClass that has a private integer data member named value, a constructor that initalizes value and to -1 (negative one) by default, and three public member functions, one to set the value of value, and one to return the value of value, and one to print the value of value. Your declaration must be consistent with the remaining parts of this question. The following statements are to be written as they would appear in a driver program, not in the class definition.

  1. Write a declaration of a two objects, obj_1 and obj_2, of class myClass. One is to be initialized to the default value, and one is to be initialized (by the constructor) to zero. Both objects are to be variables.
  2. Write a declaration of two objects, obj_a and obj_b, which are constants whose value members have the values 3 and 5, respectively.
  3. Write a statement that assigns the value of obj_a to obj_1.
  4. Write a statement that adds the value of obj_b to obj_2.
  5. Write a statement that prints the value of obj_b.
  6. Write code that would cause the following sequence of function calls: the constructor for myClass, main(), and then constructor for myClass again.