C++ Ch. 7 Arrays, Vectors

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Nelson.paulj
N
Nelson.paulj
Community Contributor
Quizzes Created: 1 | Total Attempts: 809
| Attempts: 809
SettingsSettings
Please wait...
  • 1/59 Questions

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

Please wait...
About This Quiz

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

C++ Ch. 7 Arrays, Vectors - Quiz

Quiz Preview

  • 2. 

    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.

    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:

  • 3. 

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

    • True

    • 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:

  • 4. 

    Which of the following is an array declaration with initalizers

    • Int n[ 10 ];

    • Int *n;

    • Int &n = 10;

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

    Correct Answer
    A. 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:

  • 5. 

    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.

    • True

    • 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:

  • 6. 

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

    • Int

    • Int1

    • Int2

    Correct Answer
    A. 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:

  • 7. 

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

    • True

    • 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:

  • 8. 

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

    • True

    • 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:

  • 9. 

    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.

    • True

    • 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:

  • 10. 

    A multidimensional array is declared as such: int array[name1][name2];

    • True

    • False

    Correct Answer
    A. True
    Explanation
    This statement is true. In the given code, a multidimensional array is declared using the "int" keyword, followed by the array name and two sets of square brackets. The names "name1" and "name2" represent the dimensions of the array. This syntax allows for the creation of a two-dimensional array, where each element can be accessed using two indices.

    Rate this question:

  • 11. 

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

    • 11

    • 12

    • 9

    • 10

    • None of the above

    Correct Answer
    A. 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:

  • 12. 

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

    • True

    • 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:

  • 13. 

    An array is a ....

    • Non consecutive group of memory locations that share the same type

    • Consecutive group of memory locations that share the same type

    • Non consecutive group of memory locations that have different types

    • Simple data structure containing identical types

    Correct Answer
    A. 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:

  • 14. 

    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.

    • True

    • 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:

  • 15. 

    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.

    • True

    • 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:

  • 16. 

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

    • True

    • 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:

  • 17. 

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

    • True

    • 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:

  • 18. 

    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?

    • 55

    • 22

    • 63

    • 78

    Correct Answer
    A. 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:

  • 19. 

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

    • True

    • 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:

  • 20. 

    A multidimensional array is declared as such:int array[ [] ];

    • True

    • False

    Correct Answer
    A. False
    Explanation
    The given statement is false because a multidimensional array in C++ cannot have an empty size for any of its dimensions. The declaration "int array[ [] ];" is invalid syntax and will result in a compilation error. In order to declare a multidimensional array, the size of each dimension must be specified.

    Rate this question:

  • 21. 

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

    • IF

    • WHILE

    • IF ELSE

    • FOR

    • None of the above

    Correct Answer
    A. 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:

  • 22. 

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

    • True

    • False

    Correct Answer
    A. 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:

  • 23. 

    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:

  • 24. 

    A multidimensional array cannot be initialized in its declaration  unlike a one-dimensional array.

    • True

    • False

    Correct Answer
    A. False
    Explanation
    A multidimensional array can be initialized in its declaration, just like a one-dimensional array. This means that you can assign values to the elements of the array at the time of its creation.

    Rate this question:

  • 25. 

    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.

    • True

    • 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:

  • 26. 

    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:

  • 27. 

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

    • True

    • 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:

  • 28. 

    Arrays with two dimensions (i.e., subscripts) often represent tables of values consisting of information arranged in ____ and __________.*Enter your answer in the form of:   word1 word2

    Correct Answer
    rows columns
    Explanation
    Arrays with two dimensions often represent tables of values consisting of information arranged in rows and columns. In this case, each element of the array can be accessed using two subscripts, where the first subscript represents the row number and the second subscript represents the column number. This allows for easy organization and retrieval of data in a tabular format.

    Rate this question:

  • 29. 

    [ ] and ( ) have the highest precedence

    • True

    • 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:

  • 30. 

    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:

  • 31. 

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

    • Will allow you to modify it during program execution

    • Will take on a random value when called

    • Will cause a compilation error

    • Does not matter because it will allow for modification later

    Correct Answer
    A. 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:

  • 32. 

    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.

    • True

    • 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:

  • 33. 

    Character arrays can also represent ________ (hint: types)

    Correct Answer
    strings
    Explanation
    think of data types

    Rate this question:

  • 34. 

    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:

  • 35. 

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

    • Type

    • Name

    • Array Size

    • Element Initializer List

    • All of the above

    Correct Answer(s)
    A. Type
    A. Name
    A. 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:

  • 36. 

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

    • True

    • False

    Correct Answer
    A. 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:

  • 37. 

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

    • 12

    • 10

    • 11

    • 9

    Correct Answer
    A. 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:

  • 38. 

    Const int rows = 2;const int columns = 3;int array1[ rows ][ columns ] = { { 1, 2 } } , { 4 } };The outputs will be:

    • 1 2 4

    • 1 2 0 4 0 0

    • 1 2 0 0 4 0

    • 1 2 0 4 0

    Correct Answer
    A. 1 2 0 4 0 0
    Explanation
    The given code declares a 2D array named "array1" with 2 rows and 3 columns. The array is initialized with the values {1, 2} in the first row and {4} in the second row. When the array is printed, it will display the values in row-major order. Since the second row has only one element, the remaining two elements in the second row will be initialized with the default value of 0. Therefore, the correct output will be "1 2 0 4 0 0".

    Rate this question:

  • 39. 

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

    • Run time

    • Program termination

    • The middle point of execution

    • Compilation

    Correct Answer
    A. 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:

  • 40. 

    This is a static arrayint n[];

    • True

    • False

    Correct Answer
    A. 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:

  • 41. 

    Arrays with multiple dimensions are known as ______ by _________ arrays.*Enter your answer in the form of:   word1 word2 (with a space separating answers)

    Correct Answer
    m n
    Explanation
    Arrays with multiple dimensions are known as multi-dimensional arrays. The "m" represents the number of rows in the array, while the "n" represents the number of columns. Therefore, the correct answer is multi-dimensional arrays.

    Rate this question:

  • 42. 

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

    • Size does not need to be declared

    • Size should be declared as type double

    • Size should be declared as a constant

    • Nothing

    Correct Answer
    A. 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:

  • 43. 

    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.

    • True

    • False

    Correct Answer
    A. 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:

  • 44. 

    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:

  • 45. 

    Vectors are declared as such:

    • Vector< type > size (name);

    • Vector< type > name (size);

    • Vector< name > type (size);

    • Type < vector > name (size);

    Correct Answer
    A. Vector< type > name (size);
    Explanation
    The correct answer is "vector< type > name (size);" because this is the correct syntax for declaring a vector in C++. The keyword "vector" is followed by angle brackets containing the data type of the elements in the vector. Then, the name of the vector is specified, followed by parentheses containing the desired size of the vector. This syntax creates a vector object with the specified data type and size.

    Rate this question:

  • 46. 

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

    • Yes

    • No

    Correct Answer
    A. 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:

  • 47. 

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

    • True

    • False

    Correct Answer
    A. 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:

  • 48. 

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

    • True

    • False

    Correct Answer
    A. 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:

  • 49. 

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

    • True

    • False

    Correct Answer
    A. 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:

Quiz Review Timeline (Updated): Feb 20, 2023 +

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.