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 | Questions: 59
Please wait...
Question 1 / 59
0 %
0/100
Score 0/100
1. ____________ are data structures consisting of related data items of the same type

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.

Submit
Please wait...
About This Quiz
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

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.

Submit
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).

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.

Submit
4. Which of the following is an array declaration with initalizers


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.

Submit
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.

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.

Submit
6. Which is the array name?

int int1[ int2 ];

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".

Submit
7. Static int array1[ arraySize];

Will initialize each element to 0 the first time it is called.

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.

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

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.

Submit
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.

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.

Submit
10. A multidimensional array is declared as such:

int array[name1][name2];

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.

Submit
11. Int n[11];

What is the last index number (or subscript) of this array?

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.

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

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.

Submit
13. An array is a ....

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.

Submit
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.

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.

Submit
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.

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.

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

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.

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

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.

Submit
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?

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.

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

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.

Submit
20. A multidimensional array is declared as such:

int array[ [] ];

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.

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

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.

Submit
22. This statement will not compile

int array[] = {1, 2, 3, 4};

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.

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

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".

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

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.

Submit
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.

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.

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

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.

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

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.

Submit
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

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.

Submit
29. [ ] and ( ) have the highest precedence

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.

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

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.

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

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.

Submit
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.

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.

Submit
33. Character arrays can also represent ________ (hint: types)

Explanation

think of data types

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

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.

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

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.

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

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.

Submit
37. Int n[11];

How many possible elements can be stored in this array?

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.

Submit
38. Const int rows = 2;
const int columns = 3;

int array1[ rows ][ columns ] = { { 1, 2 } } , { 4 } };

The outputs will be:

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".

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

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.

Submit
40. This is a static array

int n[];

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.

Submit
41. Arrays with multiple dimensions are known as ______ by _________ arrays.

*Enter your answer in the form of:   word1 word2 (with a space separating answers)

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.

Submit
42. What is wrong with this code?

int SIZE = 7;

int array[ SIZE ];

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".

Submit
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.

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.

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

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.

Submit
45. Vectors are declared as such:

Explanation

The correct answer is "vector 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.

Submit
46. Const int x;

x = 7;

Will this compile?

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.

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

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.

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

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.

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

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.

Submit
50. Void function1( array );

This function will operate correctly, receiving values from the array.

Explanation

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

Submit
51. Void function1( array[] );

This function will operate correctly, receiving values from the array.

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.

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

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.

Submit
53. Brackets ' [ ' have a higher precedence than ' ( '

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.

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

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.

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

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.

Submit
56. Arrays with 2 dimensions are called ___________

Explanation

Arrays with 2 dimensions are called two dimensional arrays or 2-D arrays. This is because they have two levels of indexing, allowing data to be stored and accessed in a grid-like structure with rows and columns. The first index represents the row and the second index represents the column. This type of array is commonly used in applications where data needs to be organized in a tabular format, such as matrices or spreadsheets.

Submit
57. Bubble Sort

The 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).

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.

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

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.

Submit
59. Select all that apply.

Vectors are more powerful than arrays because:

Explanation

Vectors are more powerful than arrays because they can be compared to other vectors with equality operators, vectors can be assigned to one another with the assignment operators, one vector's contents can be copied to another using its copy constructor, and they provide bounds checking, something that can't be done with arrays.

Submit
View My Results

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
Cancel
  • All
    All (59)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
____________ are data structures consisting of related data items of...
To refer to a particular location or element in the array, we specify...
The position number is more formally called a subscript or index (this...
Which of the following is an array declaration with initalizers
The value of the name of the array is the address in the computer’s...
Which is the array name?int int1[ int2 ];
Static int array1[ arraySize];Will initialize each element to 0 the...
A subscript/index must be an integer or integer expression (using any...
If the array size is omitted from a declaration with an initializer...
A multidimensional array is declared as such: ...
Int n[11];What is the last index number (or subscript) of this array?
Pass by reference means that the calling function can read and write...
An array is a ....
If a static array is not initialized explicitly by you, each element...
When passing an array to a function, the array size is normally passed...
C++ passes arrays to functions by reference—the called functions can...
The name of the array is the address in the computers memory of the...
In the statement:int a [ arraySize ] = { 87, 64, 52, 4, 45, 63, 55,...
Although entire arrays are passed by reference, individual array...
A multidimensional array is declared as such:int array[ [] ];
What is the most dominant method for accessing and printing an entire...
This statement will not compileint array[] = {1, 2, 3, 4};
Arrays are always _______ structures because they remain the same size...
A multidimensional array cannot be initialized in its...
Applying 'static' to an array declaration will allow the array not to...
Providing more initializers in an array initializer list than there...
Passing arrays by value would mean that each element would be copied...
Arrays with two dimensions (i.e., subscripts) often represent tables...
[ ] and ( ) have the highest precedence
The first element in every array has subscript ______ and is sometimes...
Not assigning a value to a constant variable when it is declared....
Only constants can be used to declare the size of automatic and status...
Character arrays can also represent ________ (hint: types)
An array is a _____________ group of memory locations that all have...
In order to declare an array of a certain size, you must indicate...
It is good practice to declare more than one array per declaration to...
Int n[11];How many possible elements can be stored in this array?
Const int rows = 2;const int columns = 3;int array1[ rows ][ columns ]...
At ___________ , the compiler reserves the appropriate amount of...
This is a static arrayint n[];
Arrays with multiple dimensions are known as ______ by _________...
What is wrong with this code?int SIZE = 7;int array[ SIZE ];
If the array size is omitted from a declaration with an initializer...
The linear search compares each element of an array with a __________
Vectors are declared as such:
Const int x;x = 7;Will this compile?
C++ passes arrays to functions by value—the called functions can...
Pass by value means that the calling function can read and write to...
If a static array is not initialized explicitly by you, the program...
Void function1( array ); ...
Void function1( array[] );This function will operate correctly,...
A program initializes static local arrays when their declarations are...
Brackets ' [ ' have a higher precedence than ' ( '
Defining the size of each array as a constant variable instead of a...
_________ sort is a simple, but inefficient, sorting algorithm.
Arrays with 2 dimensions are called ___________
Bubble SortThe first iteration of this algorithm takes the second...
To pass an element of an array to a function, use the array name as an...
Select all that apply. Vectors are more powerful than arrays because:
Alert!

Advertisement