                          Computer Science 101
                               Quiz A      Name ______________________

1. Suppose I declare an array as:  int table[10];
   The valid set of indexes that I can use to reference elements of
   the array are:

   a. table[0] ... table[10]             b. table[1] ... table[10]

   c. table[0] ... table[9]              d. table[1] ... table[9]

2. In C, if I accidentally use a value of ndx that is NOT in the valid
   set of indexes in the statement:  table[ndx] = 13;  (Circle all
   that apply)

   a. the error will be detected         b. Other data within my
      by the C compiler and my program      program may be overwritten
      can not be compiled until I           with a value of 13.
      correct the problem.

   c. The array will be automagically    d. If ndx is sufficiently far
      enlarged in size so that no           out of bounds execution of
      problem will occur.                   my program may be terminated
                                            because of a memory protection
                                            violation.

3. After the following loop executes what will be the value of
   nums[2]?

   nums[0] = 3;
   ndx = 1;
   while (ndx < 100)
   {
      nums[ndx] = 2 * nums[ndx - 1] - 2;
      ndx = ndx + 1;
   }

   nums[2] =


4. Consider the following code which is designed to read values into consecutive
   array elements and set "counter" to the number of values read.

   counter = 0;
   howmany = fscanf(stdin, "%d", &values[0]);
   while (howmany == 1)
   {
      howmany = fscanf(stdin, "%d", &values[counter]);
      counter = counter + 1;
   }

   Which best describes the operation of the program:

   a. it works correctly                 b. it counts correctly but the
                                            values read are assigned to
                                            incorrect array elements.

   c. it assigns the values to the       d. counter will be incorrect AND
      proper array elements but sets        values will be read into
      counter incorrectly                   incorrect array locations.
