< previous page page_1040 next page >

Page 1040
13. Given a class named IntList, which of the following is the correct function prototype for the class copy-constructor?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. void IntList ( IntList otherList );
b. IntList( IntList& otherList );
c. IntList( const IntList otherList );
d. void IntList( const IntList& otherList );
e. IntList( const IntList& otherList );
14. How can the use of pointers make a program run faster?
Programming Warm Up Exercises
1. a. Declare a pointer variable p and initialize it to point to a char variable named ch.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Declare a pointer variable q and initialize it to point to the first element of a long array named arr.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Declare a pointer variable r and initialize it to point to a variable named box of type
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
struct BoxType
{
    int length;
    int width;
    int height;
};
2. Using the variables p, q, and r of Exercise 1, write code to do the following:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Store @ into the variable pointed to by p.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Store 959263 into the first element of the array pointed to by q.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Store a length, width, and height of 12, 14, and 5 into the variable pointed to by r.
3. Write a Boolean value-returning function that takes two pointer variablesptr1 and ptr2as parameters. Both variables point to float data. The function should return TRUE if the two pointers point to the same variable, and FALSE otherwise.
4. Write a Boolean value-returning function that takes two pointer variablesptr1 and ptr2as parameters. Both variables point to float data. The function should return TRUE if the values in the pointed-to variables are identical, and FALSE otherwise.
5. Given the code segment
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
struct GradeType
{
    int score;
    char grade;
};
typedef GradeType* PtrType;

 
< previous page page_1040 next page >