Key for CS 102 Test 2, April 21, 2011

1.  int reverse (int a[], int b[])
    {
      int i, flag = 1;
      for(i = 0; i < N && flag; i++)
        if(a[i] != b[N-1-i])
          flag = 0;
      return flag;
    }

2A.  a.  A[i] holds zero.          b.  A holds no zeros.

2B.  a.  5    b. 0    c. 5

3.  a.  the index of the first occurrence of target in the array
    b.  the index of the last occurrence of target in the array
    c.  the target does not occur in the array
    d.  1             e.  6

4.  int mystrlen (char *s)
    {
      int i;
      for (i = 0; s[i] != '\0'; i++);
      return i;
    }

5A.   r  m

5B.  a.  strcpy(schedule[9].title, "CS 102");
     b.  extra = schedule[0];

6A.  0  92  37  82  12  10  25  60 
6B.  it returns 1 if A and B hold the same values, 0 otherwise.

7A.  int A[10][4];

7B.  a.  1. new allocates the requested amount of space from the heap 
            (or freestore).
         2. new returns the address of the allocated space.

     b.  1.  delete returns to the heap (or freestore) the space pointed 
             to by its argument.
         2.  The pointer is then undefined.

8.  a.  v_two = v_one;         b.  strcpy (c_two, c_one);
    c.  cpp_two = cpp_one;     d.  stru_two = stru_one;

    e.  int i;
        for (i = 0; i < N; i++)
          a_two[i] = a_one[i];
 
9A.  a.  2         b.  The array must be ordered.

9B.  Pass 1:  11  44  99  22  55  33  66 
     Pass 2:  11  22  99  44  55  33  66