Computer Science 2610
Summer 2000
Practice questions for exam 3

This is a closed book exam. You may bring one page of prepared notes. You have 90 minutes.

  1. A dangling pointer is
    1. a pointer to memory that has been deleted.
    2. a pointer to memory that is no longer in use.
    3. a pointer to memory that also has other pointers to it.
    4. a pointer that was created by using new.

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

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

  4. The run-time stack is characterized by
    1. automatic allocation and automatic deallocation of memory
    2. automatic allocation and explicit deallocation of memory.
    3. explicit allocation and automatic deallocation of memory.
    4. explicit allocation and explicit deallocation of memory.

  5. The heap is characterized by
    1. automatic allocation and automatic deallocation of memory
    2. automatic allocation and explicit deallocation of memory.
    3. explicit allocation and automatic deallocation of memory.
    4. explicit allocation and explicit deallocation of memory.

  6. 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);

  7. 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.

  8. When passing a two-dimensional array as a parameter, which of the following must be given along with the formal parameter?
    1. The physical number of columns (the second index).
    2. The physical number of rows (the first index).
    3. The logical number of columns (the second index).
    4. The logical number of rows (the first index).

  9. The dynamic programming solution to the edit distance problem is based on filling in an array d, where d[i][j] is the edit distance between the length i prefix of A and the length j prefix of B. Which of the following is true?
    1. d[i][0] = 0.
    2. d[i][0] = i.
    3. d[i][0] = i-1 .
    4. d[i][0] = i+1.

  10. 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];

  11. 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

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

  13. 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;
         }
    

  14. Using the list abstraction presented in class (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. Do not violate the abstraction by making assumptions about the list implementation. Only use the functions that are provided.
    bool allPositive(List L)
    

  15. Write a function matrixAdd(A,B,C) that takes as parameters three 10x10 arrays A, B and C. Each of those arrays holds integers. Function matrixAdd should set each member of array C to the sum of the corresponding members of A and B. For example, C[1][2] should be set to A[1][2] + B[1][2].
     void matrixAdd(double A[10][10], 
                    double B[10][10], 
                    double C[10][10])