Computer Science 2610
Fall 2000
Practice questions for quiz 4

  1. If Node is a type, then expression new Node returns a value of type
    1. Node
    2. Node*
    3. Node**
    4. Node&

  2. The C++ keyword used to return memory to the pool of available memory is
    1. new
    2. free
    3. release
    4. delete

  3. Which of the following will copy the null-terminated string that is in array src into array dest?
    1. dest = src;
    2. dest == src;
    3. strcpy(dest, src);
    4. strcpy(src, dest);

  4. A pointer is a memory address. Suppose that pointer variable p holds address 1000, and that p is declared to have type int*. Suppose that an int is 4 bytes long. What address is represented by expression p+2?
    1. 1002
    2. 1004
    3. 1008
    4. None. This expression is not allowed.

  5. Which of the following allocates a new array A in the heap, holding 10 bytes?
    1. char A[10];
    2. int A[10];
    3. char* A = new char[10];
    4. int* A = new int[10];

  6. Which of the following is true if null-terminated strings A and B are the same string?
    1. strcmp(A,B) != 0
    2. strcmp(A,B) == 0
    3. A = B
    4. A == B

  7. What is the tail of list [6,2]?
    1. 6
    2. 2
    3. [6]
    4. [2]

  8. What is printed by the function fourteen when it is run?
         void fourteen()
         {
            int* s;
            int* p = new int;
            int* q = p;
            int* r = new int;
            *p = 8;
            s = p;
            *q = 25;
            *r = *s;
            q = r;
            cout << "*p = " << *p << endl;
            cout << "*q = " << *q << endl;
            cout << "*r = " << *r << endl;
            cout << "*s = " << *s << endl;
         }
    

  9. Write a function that returns a copy of a null-terminated string. The copy should be put into memory that is allocated using new, and it should be null-terminated. Return a pointer to the new memory.

  10. Using the list type and operations presented in class (type List and operations head, tail, cons and emptyList) write a function allPositive(L) that returns 1 if all members of list L are positive numbers, and returns 0 otherwise.
    bool allPositive(List L)