C++ Ch 7 Arrays Quiz

29 Questions | Total Attempts: 624

SettingsSettingsSettings
Please wait...
C++ Ch 7 Arrays Quiz

Quiz over Arrays in C++


Questions and Answers
  • 1. 
    Name 3 types of sorts used with arrays.
  • 2. 
    The locations of the various indexed variables in an array can be spread out all over the memory.
    • A. 

      True

    • B. 

      False

  • 3. 
    If a function is expecting a pass by reference parameter, you can pass an index variable from an array of the same base type to that function.
    • A. 

      True

    • B. 

      False

  • 4. 
    When you have a function that expects an array, it should also expect the size of the array or the number of indexed variables with valid data.
    • A. 

      True

    • B. 

      False

  • 5. 
    The following function declaration guarantees the values in the array argument are not changed. void function1(int array[], int numElements);
    • A. 

      True

    • B. 

      False

  • 6. 
    The following function will work with any size integer array. void function1(int array[], int numElements);
    • A. 

      True

    • B. 

      False

  • 7. 
    What are the valid indexes for the array shown below? int myArray[25];
    • A. 

      0-25

    • B. 

      0-24

    • C. 

      1-25

    • D. 

      1-24

  • 8. 
    Why should you use a named constant for the size of an array?
    • A. 

      Readability of code

    • B. 

      Makes changes to the program easier

    • C. 

      Helps reduce logic errors

    • D. 

      All answers are correct

  • 9. 
    What is wrong with the following code fragment? const int SIZE =5; float scores[SIZE]; for(int i=0; i<=SIZE;i++) { cout << "Enter a score\n"; cin >> scores[i]; }
    • A. 

      Array indexes start at 1 not 0

    • B. 

      Arrays must be integers

    • C. 

      Array indexes must be less than the size of the array

    • D. 

      Should be cin >> scores[0];

  • 10. 
    Which of the following declare an array of 5 characters, and initializes them to some known values?
    • A. 

      Char array[5]={'a','b','c','d','e'};

    • B. 

      Char array[4]={'a','b','c','d','e'};

    • C. 

      Char array[5]={' '};

    • D. 

      Char array[]={'a','b','d','e'};

    • E. 

      Char array[5]={'a','b','c','d','e'}; and char array[5]={' '};

  • 11. 
    Arrays are always passed to a function using
    • A. 

      Pass by value

    • B. 

      Pass by reference

    • C. 

      Pass by array

    • D. 

      You cannot pass arrays to a function

  • 12. 
    Give the following declarations, which of the following is a legal call to this function? int myFunction(int myValue); int myArray[1000];
    • A. 

      Cout

    • B. 

      Cout

    • C. 

      MyArray[1] = myFunction(myArray[0]);

    • D. 

      Cout

  • 13. 
    Which of the following function declarations correctly guarantee that the function will not change any values in the array argument?
    • A. 

      Void f1(int array[], int size) const;

    • B. 

      Void f1(int array[], int size);

    • C. 

      Void f1(int &array, int size);

    • D. 

      Void f1(const int array[], int size);

  • 14. 
    If we want a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate?
    • A. 

      Void search(const int array, int target, int numElements);

    • B. 

      Void search(const int array, int target);

    • C. 

      Int search(const int array[], int numElements);

    • D. 

      Int search(const int array[], int target, int numElements

  • 15. 
    Given the following function definition, will repeated calls to the search function for the same target find all occurrences of that target in the array? int search(const int array[], int target, int numElements) { int index=0; bool found=false; while((!found) && (index < numElements)) { if(array[index] == target) found=true; else index++; } if(found==true) return index; else return -1; }
    • A. 

      Yes

    • B. 

      No

    • C. 

      Impossible to tell without looking at the values of the array

    • D. 

      It depends on the value of target.

  • 16. 
    Which of the following function declarations will accept the following two- dimension array? int pages[10][30];
    • A. 

      Void f1(int pages[][], int size);

    • B. 

      Void f1(int pages[][30], int size);

    • C. 

      Void f1(int pages[10][], int size);

    • D. 

      Void f1(int& pages, int size);

  • 17. 
    If you need a function that will handle multi-dimensional arrays, you must specify the following sizes inside the square brackets.
    • A. 

      All the sizes

    • B. 

      All sizes except the last dimension

    • C. 

      All sizes except the first dimension

    • D. 

      None of the sizes

  • 18. 
    What is the output of the following code fragment? int array[4][4], index1, index2; for(index1=0;index1<4;index1++) for(index2=0;index2<4;index2++) array[index1][index2]=index1 + index2; for(index1=0;index1<4;index1++) { for(index2=0;index2<4;index2++) cout << array[index1][index2] << " "; cout << endl; }
    • A. 

      0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6

    • B. 

      0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3

    • C. 

      0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3

    • D. 

      0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9

  • 19. 
    Which of the following function declarations can be passed the following array? char myArray[6][8];
    • A. 

      Void f1(char a[][], int sizeOfFirst);

    • B. 

      Void f1(char a[][8], int sizeOfFirst);

    • C. 

      Void f1(char a[6][8], int sizeOfFirst);

    • D. 

      Void f1(char a[][8], int sizeOfFirst); and void f1(char a[6][8], int sizeOfFirst);

  • 20. 
    A two dimension array can also be thought of as
    • A. 

      A table

    • B. 

      An array of arrays

    • C. 

      A file

    • D. 

      A table and an array of arrays

  • 21. 
    Which of the following will correctly assign all the values in one array to the other array? (Assume both arrays are of the same type and have SIZE elements)
    • A. 

      Array1=array2;

    • B. 

      Array1[]=array2;

    • C. 

      Array1[]=array2; c. for(i=0;i

    • D. 

      For(i=0;i

  • 22. 
    Memory for the formal parameters and variables declared in the body of a function is a / an
    • A. 

      Local variable

    • B. 

      Local identifier

    • C. 

      Automatic variable

  • 23. 
    What refers to where in the program an identifier is accessible (visible)?
    • A. 

      Scope of an identifier

    • B. 

      Reference parameter

    • C. 

      Scope resolution operator

    • D. 

      Static Variable

  • 24. 
    What type of variable do you have when the memory for the variable remains allocated as long as the program executes?
    • A. 

      Static

    • B. 

      Automatic

    • C. 

      Instance

    • D. 

      Local

  • 25. 
    What is the correct way to create an array named golfScores that witll hold 5 game scores.
    • A. 

      Int golfScores[5];

    • B. 

      Float golfScores[5];

    • C. 

      Int golfScores;

    • D. 

      String golfScores[]