Module 9. Subscripted Variables and Pointers Exercise Answers

1.  Can't assign using index 10; valid indices are 0 to 9.

2.  Wrong.  Every item in an array must be of the same type.

3.  Wrong.  Arrays are always passed by reference.

4.  (a) 2, (b) 1, (c) k

5.
    // Declare any local variable
    int i;

    // Initialize the first two numbers in the array F
    F[0] = 0;
    F[1] = 1;

    // Use a loop to generate the rest
    for (i=2; i < fib_num; i++) 
    {
       F[i] = F[i-1] + F[i-2];
    }

6.
   int BinSearch (int A[], int Element, int First, int Last)
   {
    int Mid;

    if(First > Last)
    {
      return(-1);       // not found; 
    } 
    else 
    {
      Mid = (First + Last) / 2;
      if(Element == A[Mid])
          return(Mid);
      else 
      {
          if (Element < A[Mid])
             return(BinSearch(A,Element,First,Mid-1));
          else 
             return(BinSearch(A,Element,Mid+1,Last);
      }
    }
   }

7.  
  int* zolish;
  zolish = &xerxes;
  *zolish = 45;

8.  45

9.  
  float* salary;
  salary = new float;
  *salary = 150.75;

10.  
  delete salary;

11.  pixel = 24; pad = 57; lane = pointer to pixel; dots = pointer to
pad