C++ Ch. 7 Arrays, Vectors

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Nelson.paulj
N
Nelson.paulj
Community Contributor
Quizzes Created: 1 | Total Attempts: 739
Questions: 59 | Attempts: 739

SettingsSettingsSettings
C++ Ch. 7 Arrays, Vectors - Quiz

Tests on C++ data structure concepts such as arrays and vectors
Complete CH 7 theory.
PASS >= 70
62 questions
No time limit


Questions and Answers
  • 1. 

    An array is a ....

    • A.

      Non consecutive group of memory locations that share the same type

    • B.

      Consecutive group of memory locations that share the same type

    • C.

      Non consecutive group of memory locations that have different types

    • D.

      Simple data structure containing identical types

    Correct Answer
    B. Consecutive group of memory locations that share the same type
    Explanation
    An array is a consecutive group of memory locations that share the same type. This means that the elements of an array are stored in contiguous memory locations, and all the elements in the array have the same data type. This allows for efficient access to the elements of the array using indexing.

    Rate this question:

  • 2. 

    ____________ are data structures consisting of related data items of the same type

    Correct Answer
    arrays, Arrays, Array
    Explanation
    Arrays are data structures that consist of related data items of the same type. They allow for the storage and retrieval of multiple values under a single variable name. Arrays can hold elements such as numbers, characters, or objects, and they are accessed using an index. The given answer includes the plural form "arrays" and the singular form "Array," indicating that both multiple and single instances of this data structure are included. The capitalized "Arrays" suggests that it may be referring to a specific programming language's implementation of arrays.

    Rate this question:

  • 3. 

    Arrays are always _______ structures because they remain the same size throughout execution

    Correct Answer
    static
    Explanation
    Arrays are considered "static" structures because their size does not change during the execution of a program. Once an array is created, it is allocated a fixed amount of memory to store its elements. This means that the size of the array remains constant and does not dynamically adjust based on the program's needs. Therefore, the correct answer is "static".

    Rate this question:

  • 4. 

    Character arrays can also represent ________ (hint: types)

    Correct Answer
    strings
    Explanation
    think of data types

    Rate this question:

  • 5. 

    An array is a _____________ group of memory locations that all have the same type.

    Correct Answer
    consecutive
    Explanation
    An array is a consecutive group of memory locations that all have the same type. This means that the memory locations for the elements of an array are allocated in a contiguous manner, one after the other. This allows for efficient access and manipulation of array elements using their indices. By having the elements stored consecutively, the array can be easily traversed and processed in a systematic manner.

    Rate this question:

  • 6. 

    To refer to a particular location or element in the array, we specify the name of the array and the position  _______ of the particular element.

    Correct Answer
    number, index
    Explanation
    To refer to a particular location or element in the array, we specify the name of the array and the position index of the particular element. The index is a numerical value that represents the position of an element in the array. It starts from 0 for the first element and increments by 1 for each subsequent element. By using the index, we can access and manipulate specific elements in the array.

    Rate this question:

  • 7. 

    The position number is more formally called a subscript or index (this number specifies the number of elements from the beginning of the array).

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The position number in an array is indeed more formally called a subscript or index. This number represents the number of elements from the beginning of the array, allowing us to access specific elements within the array by their position. Therefore, the statement is true.

    Rate this question:

  • 8. 

    The first element in every array has subscript ______ and is sometimes called the _____th element.

    Correct Answer
    zero, 0
    Explanation
    The first element in every array has a subscript of zero and is sometimes called the 0th element. This is because in most programming languages, arrays are zero-indexed, meaning that the first element is accessed using the index 0.

    Rate this question:

  • 9. 

    A subscript/index must be an integer or integer expression (using any integral type).

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    This statement is true because a subscript or index in programming is used to access elements in an array or a collection. In most programming languages, the subscript or index must be an integer or an expression that evaluates to an integer. This is because arrays are typically implemented using memory addresses, which are integer values. Using non-integer values as subscripts would result in undefined behavior or errors in the program.

    Rate this question:

  • 10. 

    Brackets ' [ ' have a higher precedence than ' ( '

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Brackets ' [ ' do not have a higher precedence than ' ( '. In mathematical expressions, parentheses ' ( ' have the highest precedence, followed by brackets ' [ ', and then by other operators. This means that any operations enclosed within parentheses should be evaluated first, regardless of whether there are brackets involved. Therefore, the correct answer is False.

    Rate this question:

  • 11. 

    [ ] and ( ) have the highest precedence

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The statement is true because both square brackets [ ] and parentheses ( ) have the highest precedence in mathematical operations. This means that any calculations or operations within these symbols will be performed first before any other operations.

    Rate this question:

  • 12. 

    In order to declare an array of a certain size, you must indicate three things. Check all that apply

    • A.

      Type

    • B.

      Name

    • C.

      Array Size

    • D.

      Element Initializer List

    • E.

      All of the above

    Correct Answer(s)
    A. Type
    B. Name
    C. Array Size
    Explanation
    To declare an array of a certain size, you need to indicate the type of elements in the array, the name of the array, and the size of the array. These three things are necessary to properly declare an array. The element initializer list is not required when declaring an array, as it is used to initialize the elements of the array with specific values. Therefore, the correct answer is Type, Name, and Array Size.

    Rate this question:

  • 13. 

    At ___________ , the compiler reserves the appropriate amount of memory (arrays).

    • A.

      Run time

    • B.

      Program termination

    • C.

      The middle point of execution

    • D.

      Compilation

    Correct Answer
    D. Compilation
    Explanation
    During the compilation phase, the compiler analyzes the code and determines the appropriate amount of memory that needs to be reserved for arrays. This is because arrays require a fixed amount of memory to store their elements. Therefore, at compilation, the compiler calculates the size of the array and allocates the necessary memory space for it.

    Rate this question:

  • 14. 

    It is good practice to declare more than one array per declaration to enhance readability.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Declaring more than one array per declaration does not necessarily enhance readability. In fact, it can make the code more confusing and harder to understand. It is generally recommended to declare each array separately to improve code clarity and maintainability. Therefore, the given statement is false.

    Rate this question:

  • 15. 

    Which of the following is an array declaration with initalizers

    • A.

      Int n[ 10 ];

    • B.

      Int *n;

    • C.

      Int &n = 10;

    • D.

      Int n[10] = { 1, 2, 3, 4, 5 };

    Correct Answer
    D. Int n[10] = { 1, 2, 3, 4, 5 };
    Explanation
    The correct answer is "int n[10] = { 1, 2, 3, 4, 5 };". This is an array declaration with initializers because it declares an array named "n" with a size of 10 and initializes it with the values 1, 2, 3, 4, and 5.

    Rate this question:

  • 16. 

    What is the most dominant method for accessing and printing an entire array.

    • A.

      IF

    • B.

      WHILE

    • C.

      IF ELSE

    • D.

      FOR

    • E.

      None of the above

    Correct Answer
    D. FOR
    Explanation
    The most dominant method for accessing and printing an entire array is using the FOR loop. The FOR loop allows us to iterate over each element of the array and perform the desired operations, such as printing the values. It provides a concise and efficient way to access and process all the elements in the array without the need for complex conditional statements.

    Rate this question:

  • 17. 

    This statement will not compileint array[] = {1, 2, 3, 4};

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The given statement will compile successfully. It declares an integer array named "array" and initializes it with the values 1, 2, 3, and 4. Therefore, the correct answer is False.

    Rate this question:

  • 18. 

    If the array size is omitted from a declaration with an initializer list, the compiler determines the number of elements in the array by counting the number of elements in the initializer list.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When the array size is not specified in the declaration and an initializer list is provided, the compiler will automatically count the number of elements in the initializer list to determine the size of the array. This allows for a more convenient and flexible way of initializing arrays without having to manually specify the size. Therefore, the given answer "True" is correct.

    Rate this question:

  • 19. 

    If the array size is omitted from a declaration with an initializer list, the compiler determines the number of elements in the array by accessing the closest constant integer to the statement.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    If the array size is omitted from a declaration with an initializer list, the compiler does not determine the number of elements in the array by accessing the closest constant integer to the statement. Instead, it will result in a compiler error because the size of the array cannot be determined. Therefore, the given statement is false.

    Rate this question:

  • 20. 

    Int n[11];How many possible elements can be stored in this array?

    • A.

      12

    • B.

      10

    • C.

      11

    • D.

      9

    Correct Answer
    C. 11
    Explanation
    The array "n" has a size of 11, which means it can store a total of 11 elements. Each element in the array can be accessed using an index value ranging from 0 to 10. Therefore, the correct answer is 11.

    Rate this question:

  • 21. 

    Int n[11];What is the last index number (or subscript) of this array?

    • A.

      11

    • B.

      12

    • C.

      9

    • D.

      10

    • E.

      None of the above

    Correct Answer
    D. 10
    Explanation
    The last index number (or subscript) of this array is 10. This is because arrays in most programming languages start indexing from 0, so an array with a size of 11 will have indices ranging from 0 to 10.

    Rate this question:

  • 22. 

    Providing more initializers in an array initializer list than there are ___________ in the array is a compilation error.

    Correct Answer
    elements, indexs, positions
    Explanation
    If more initializers are provided in an array initializer list than there are elements in the array, it will result in a compilation error. In other words, if the number of values specified in the initializer list exceeds the size of the array, the compiler will throw an error because there are not enough elements in the array to store all the provided values. Similarly, if the initializer list contains more values than the number of positions or indexes in the array, it will also lead to a compilation error.

    Rate this question:

  • 23. 

    What is wrong with this code?int SIZE = 7;int array[ SIZE ];

    • A.

      Size does not need to be declared

    • B.

      Size should be declared as type double

    • C.

      Size should be declared as a constant

    • D.

      Nothing

    Correct Answer
    C. Size should be declared as a constant
    Explanation
    In this code, the variable "SIZE" is used to determine the size of the array. However, it is not declared as a constant. By declaring it as a constant, it ensures that the value of "SIZE" cannot be changed throughout the program. This is important because the size of an array should not be modified once it is declared. Therefore, the correct answer is that "size should be declared as a constant".

    Rate this question:

  • 24. 

    Not assigning a value to a constant variable when it is declared....

    • A.

      Will allow you to modify it during program execution

    • B.

      Will take on a random value when called

    • C.

      Will cause a compilation error

    • D.

      Does not matter because it will allow for modification later

    Correct Answer
    C. Will cause a compilation error
    Explanation
    When a constant variable is declared, it is expected to have a fixed value that cannot be changed during program execution. Therefore, not assigning a value to a constant variable when it is declared will cause a compilation error. This is because the compiler requires a constant variable to have an initial value that remains constant throughout the program.

    Rate this question:

  • 25. 

    Const int x;x = 7;Will this compile?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    The given code will not compile because it is declaring a constant variable "x" without initializing it. In C++, constant variables must be initialized at the time of declaration. Therefore, the code will result in a compilation error.

    Rate this question:

  • 26. 

    Only constants can be used to declare the size of automatic and status arrays. Not using a constant for this purpose is a compilation error.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Using constants to declare the size of automatic and status arrays is necessary because the size of these arrays needs to be known at compile time. If a non-constant value is used, it would not be possible for the compiler to determine the size of the array, resulting in a compilation error. Therefore, the statement that only constants can be used to declare the size of these arrays is true.

    Rate this question:

  • 27. 

    Defining the size of each array as a constant variable instead of a literal constant can make programs less scalable.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Defining the size of each array as a constant variable instead of a literal constant does not necessarily make programs less scalable. In fact, using constant variables can improve program scalability as it allows for easier modification of array sizes without altering the code. This flexibility is especially useful when dealing with dynamic data or when the size of the array needs to be determined at runtime.

    Rate this question:

  • 28. 

    In the statement:int a [ arraySize ] = { 87, 64, 52, 4, 45, 63, 55, 22, 78 };What is the element that is in the 7th index position?

    • A.

      55

    • B.

      22

    • C.

      63

    • D.

      78

    Correct Answer
    B. 22
    Explanation
    The given statement declares an array of integers named "a" with a size of "arraySize" and initializes it with values. The values are 87, 64, 52, 4, 45, 63, 55, 22, and 78. The question asks for the element that is in the 7th index position of the array. In programming, array indices start from 0, so the 7th index position refers to the 8th element in the array. Therefore, the correct answer is 22.

    Rate this question:

  • 29. 

    Which is the array name?int int1[ int2 ];

    • A.

      Int

    • B.

      Int1

    • C.

      Int2

    Correct Answer
    B. Int1
    Explanation
    The array name in the given code snippet is "int1". In C++, the array name is used to refer to the entire array and represents the memory address of the first element of the array. In this case, "int1" is the name given to the array, which is of type "int" and has a size specified by the variable "int2".

    Rate this question:

  • 30. 

    A program initializes static local arrays when their declarations are ____________.

    • A.

      First encountered

    • B.

      Accessed

    • C.

      Terminated

    • D.

      Created

    Correct Answer
    A. First encountered
    Explanation
    Static local arrays in a program are initialized when their declarations are first encountered. This means that when the program reaches the line where the static local array is declared, it will allocate memory for the array and initialize its elements with default values. This initialization only happens once, when the array is first encountered during the execution of the program.

    Rate this question:

  • 31. 

    If a static array is not initialized explicitly by you, the program will not compile

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    If a static array is not initialized explicitly by you, the program will still compile. In C++, if an array is not initialized by the programmer, the elements of the array will be automatically initialized to their default values (0 for integers, false for booleans, etc.). This means that the program will compile and run without any issues, even if the array is not explicitly initialized. Therefore, the correct answer is False.

    Rate this question:

  • 32. 

    If a static array is not initialized explicitly by you, each element of that array is initialized to zero by the compiler when the array is created.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When a static array is not initialized explicitly by the programmer, the compiler automatically initializes each element of the array to zero when the array is created. This means that if the programmer does not assign any values to the elements of the array, they will all be set to zero by default. Therefore, the statement "If a static array is not initialized explicitly by you, each element of that array is initialized to zero by the compiler when the array is created" is true.

    Rate this question:

  • 33. 

    This is a static arrayint n[];

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The given statement declares a static array named 'n' without specifying its size or initializing its elements. Since the size of the array is not specified, it is not a valid declaration and will result in a compilation error. Therefore, the correct answer is False.

    Rate this question:

  • 34. 

    Applying 'static' to an array declaration will allow the array not to be created and initialized each time a program calls a function containing the array.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    By applying the 'static' keyword to an array declaration, the array will be created and initialized only once, and its values will be retained across multiple function calls. This means that the array will not be recreated and reinitialized each time the program calls a function containing the array. Therefore, the statement is true.

    Rate this question:

  • 35. 

    Static int array1[ arraySize];Will initialize each element to 0 the first time it is called.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The given statement is true because when an array is declared with the "static" keyword, all its elements are automatically initialized to 0 the first time it is called. Therefore, in this case, each element of the array "array1" will be initialized to 0 when it is first called.

    Rate this question:

  • 36. 

    Void function1( array[] );This function will operate correctly, receiving values from the array.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The given answer is false because the function1 declaration is missing the data type of the array parameter. In order for the function to receive values from the array correctly, the data type of the array parameter should be specified.

    Rate this question:

  • 37. 

    Void function1( array ); This function will operate correctly, receiving values from the array.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The given statement suggests that the function "function1" will correctly operate by receiving values from the array. Therefore, the correct answer is true.

    Rate this question:

  • 38. 

    When passing an array to a function, the array size is normally passed as well, so the function can process the specific number of elements in the array.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    When passing an array to a function, it is important to pass the array size as well. This allows the function to know the exact number of elements in the array and process them accordingly. Without knowing the size of the array, the function may not be able to correctly access or manipulate the elements. Therefore, passing the array size along with the array itself ensures that the function can accurately work with the array's elements.

    Rate this question:

  • 39. 

    C++ passes arrays to functions by reference—the called functions can modify the element values in the callers’ original arrays.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    In C++, arrays are passed to functions by reference, which means that the called functions can modify the values of the elements in the original arrays of the callers. This allows for the modification of array elements within a function and ensures that the changes made in the function are reflected in the original array.

    Rate this question:

  • 40. 

    C++ passes arrays to functions by value—the called functions can modify the element values in the callers’ original arrays.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In C++, arrays are passed to functions by reference, not by value. This means that the called functions can modify the element values in the caller's original array. Therefore, the statement "C++ passes arrays to functions by value" is incorrect, making the correct answer false.

    Rate this question:

  • 41. 

    The name of the array is the address in the computers memory of the first element of the array

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The statement is true because in most programming languages, the name of the array is essentially a pointer to the memory location where the first element of the array is stored. This means that when we access or manipulate the array, we are actually working with the memory address of the first element.

    Rate this question:

  • 42. 

    The value of the name of the array is the address in the computer’s memory of the first element of the array.Because the starting address of the array is passed, the called function knows precisely where the array is stored in memory.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The explanation for the given correct answer is that the value of the name of the array is indeed the address in the computer's memory of the first element of the array. This is because arrays are stored in a contiguous block of memory, and the name of the array represents the starting address of that block. When a function is called and the array is passed as an argument, the function knows exactly where the array is stored in memory because it receives the starting address. Therefore, the statement is true.

    Rate this question:

  • 43. 

    Pass by value means that the calling function can read and write to the original values.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Pass by value means that the calling function receives a copy of the original values, not the actual values themselves. Therefore, any modifications made to the parameters within the called function do not affect the original values in the calling function.

    Rate this question:

  • 44. 

    Pass by reference means that the calling function can read and write to the original values.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Pass by reference is a method of passing arguments to a function where the function can directly access and modify the original values of the variables passed to it. This means that any changes made to the variables inside the function will also affect the original values outside the function. Therefore, the statement "Pass by reference means that the calling function can read and write to the original values" is true.

    Rate this question:

  • 45. 

    Passing arrays by value would mean that each element would be copied to the calling function, thus causing a penalty in performance speeds.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Passing arrays by value means that a copy of each element in the array is made and passed to the calling function. This can result in a decrease in performance speeds because it requires additional memory and processing time to make these copies. Therefore, the statement that passing arrays by value can cause a penalty in performance speeds is true.

    Rate this question:

  • 46. 

    Although entire arrays are passed by reference, individual array elements are passed by value exactly as simple variables are.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    This statement is true because when an entire array is passed as a parameter to a function, it is passed by reference, meaning that the function can modify the original array. However, when individual array elements are passed as parameters, they are passed by value, which means that any changes made to the elements within the function will not affect the original array. This is similar to how simple variables are passed by value.

    Rate this question:

  • 47. 

    To pass an element of an array to a function, use the array name as an argument in the function call.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    To pass an element of an array to a function, you need to specify the index of the element in the array as an argument in the function call, not the array name itself. The array name represents the entire array, so passing it as an argument would pass the entire array to the function, not just a specific element. Therefore, the statement is false.

    Rate this question:

  • 48. 

    The linear search compares each element of an array with a __________

    Correct Answer
    search key, key
    Explanation
    The linear search algorithm compares each element of an array with a search key, which is also known as the key being searched for. This process continues until a match is found or the entire array has been traversed. By comparing each element with the search key, the linear search algorithm can determine if the desired element is present in the array.

    Rate this question:

  • 49. 

    _________ sort is a simple, but inefficient, sorting algorithm.

    Correct Answer
    Insertion
    Explanation
    Insertion sort is a simple sorting algorithm that works by repeatedly inserting an element from the unsorted portion of the list into its correct position in the sorted portion. It is considered inefficient for large data sets because it has a time complexity of O(n^2), making it slower than more advanced sorting algorithms like merge sort or quicksort. However, it is still useful for small data sets or partially sorted lists.

    Rate this question:

  • 50. 

    Bubble SortThe first iteration of this algorithm takes the second element and, if it’s less than the first element, swaps it with the first element (i.e., the program inserts the second element in front of the first element).

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The explanation for the given correct answer is that in the first iteration of the Bubble Sort algorithm, the program compares the second element with the first element. If the second element is smaller than the first element, they are swapped. Therefore, the program does not insert the second element in front of the first element. Hence, the answer is false.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 03, 2010
    Quiz Created by
    Nelson.paulj
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.