Next: Exercises Up: Arrays Previous: Summary

Review Questions

  1. If an array has a 100 elements what is the allowable range of subscripts?

  2. What is the difference between the expressions a4 and a[4]?

  3. Write a declaration for a 100 element array of floats. Include an initialisation of the first four elements to 1.0, 2.0, 3.0 and 4.0.

  4. An array day is declared as follows:
    int day[] = {mon, tue, wed, thu, fri};
    
    How many elements has the array day? If the declaration is changed to
    int day[7] = {mon, tue, wed, thu, fri};
    
    how many elements does day have?

  5. What would be output by the following section of C++?
    int A[5] = {1 , 2, 3, 4};
    int i;
    for (i=0; i<5; i++)
     {
      A[i] = 2*A[i];
      cout << A[i] << "  ";
     }
    

  6. What is wrong with the following section of program?
    int A[10], i;
    for (i=1; i<=10; i++)
       cin >> A[i];
    

  7. Write a function heading for a function which will double the first n elements of an array. If the function was amended so that it would return false if n was larger than the size of the array how should the function heading be written? If the function was to be changed so that a new array was produced each of whose elements were double those of the input array how would the heading be written?



Next: Exercises Up: Arrays Previous: Summary