1. Assume the variable arrayName is to be an array of 12
bytes.
- Write a statement that declares arrayName to be of
type char and reserves memory for the array.
- Write a statement that reserves memory for a pointer to a
character.
- Write two different statements that store the address of the
first (zeroth) element of arrayName in the pointer variable
you defined in answer B.
- Write a statement that uses your pointer variable to store
the value 'a' into the first element of arrayName.
- Write a statement that makes your pointer variable point to
the next element of the array.
- Which of these string constants should not be copied
into arrayName:
- "1234567890A"
- "1234567890AB"
- "1234567890ABCD"
- Write a statement that uses strcpy() to copy the string
"ABC" into arrayName.
- 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.
- 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.
- Write a statement that defines an array of 15 nodeElements.
- How much memory does this array occupy? (Assume no "filler"
or "padding" bytes are needed.)
- 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.
- Write a statement that defines a pointer to a nodeElement.
- 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.
- What is the command line to start your debugging session using
gdb?
- 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.)
- Once you get to theProblem(), how can you execute one
statement at a time?
- How can you examine the value of a variable?
- 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.
- 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.
- Write a declaration of two objects, obj_a and obj_b,
which are constants whose value members have the values
3 and 5, respectively.
- Write a statement that assigns the value of obj_a to
obj_1.
- Write a statement that adds the value of obj_b to obj_2.
- Write a statement that prints the value of obj_b.
- Write code that would cause the following sequence of function
calls: the constructor for myClass, main(), and then constructor
for myClass again.