Module 6 - Questions
Arrays:
What is an array, and why is it important in programming?
How can you create and initialize an array in your programs?
What are some common mistakes that programmers make when working with arrays, and how can they be avoided?
How can you use arrays to store and manipulate large sets of related data in your programs?
What are multi-dimensional arrays, and how can you use them to store and manipulate more complex data structures?
What is the purpose of a parallel array?
How can you optimize the performance of your programs by using arrays efficiently?
How can you use arrays to solve real-world problems in your programming projects?
Array Multiple Choice Questions
What is the index of the first element in a C++ array?
[ ] 1
[ ] 0
[ ] -1
[ ] Undefined
Which of the following correctly declares an array of integers with size 5?
[ ]
int myArray[4];
[ ]
int myArray<5>;
[ ]
int myArray[5];
[ ]
int[5] myArray;
How do you initialize an array with values at the time of declaration?
[ ]
int arr[] = (1, 2, 3);
[ ]
int arr[] = {1, 2, 3};
[ ]
int arr[3] = 1, 2, 3;
[ ]
int arr[3] = (1, 2, 3);
What happens if you try to access an element outside the bounds of an array?
[ ] Compilation error
[ ] Runtime error
[ ] Undefined behavior
[ ] The program will automatically resize the array
What is the output of the following code snippet?
int arr[] = {1, 2, 3}; cout << arr[2];
[ ] 1
[ ] 2
[ ] 3
[ ] Error
True or False Questions
T/F: Arrays in C++ are dynamic, meaning they can be resized during runtime.
T/F: The elements of an array in C++ are stored in contiguous memory locations.
T/F: You can declare an array without specifying its size if you initialize it at the time of declaration.
T/F: C++ arrays perform bounds checking when accessing elements.
T/F: It is possible to have arrays of any data type, including user-defined types.
Vector Multiple Choice Questions
Which header file must be included to use vectors in C++?
[ ]
<array>
[ ]
<vector>
[ ]
<list>
[ ]
<deque>
How do you declare an empty vector of integers?
[ ]
vector<int> vec;
[ ]
int vector vec;
[ ]
vector vec<int>;
[ ]
int vec[];
Which member function is used to add an element at the end of a vector?
[ ]
push()
[ ]
append()
[ ]
add()
[ ]
push_back()
Which of the following is NOT a member function of the vector class?
[ ]
size()
[ ]
pop_back()
[ ]
clear()
[ ]
get()
True or False Questions
T/F: Vectors in C++ are dynamic arrays that can grow or shrink at runtime.
T/F: Elements in a vector are stored in non-contiguous memory locations.
T/F: It is mandatory to specify the size of a vector at the time of its declaration.
T/F: You can use array-style indexing to access elements in a vector.
Parallel Array Multiple Choice Questions
What is a parallel array?
[ ] An array that can be accessed by multiple threads simultaneously.
[ ] Multiple arrays where corresponding elements are related.
[ ] An array that stores multiple types of data.
[ ] An array that is automatically sorted.
What is the primary advantage of using parallel arrays?
[ ] Dynamic resizing
[ ] Type safety
[ ] Memory efficiency
[ ] Built-in sorting and searching
Which operation becomes more complex when using parallel arrays?
[ ] Accessing individual elements
[ ] Calculating the length of the arrays
[ ] Inserting or deleting elements
[ ] Declaring the arrays
How do you ensure that the data in parallel arrays stays synchronized?
[ ] The arrays automatically stay synchronized.
[ ] You must manually update all arrays when making changes.
[ ] Use a special library for parallel arrays.
[ ] Use a built-in C++ feature for parallel arrays.
What is the primary disadvantage of using parallel arrays?
[ ] They are slow.
[ ] They are not supported in modern C++.
[ ] They can be error-prone and hard to manage.
[ ] They take up too much memory.
True or False Questions
T/F: Parallel arrays are a feature built into the C++ language.
T/F: In parallel arrays, the element at a given index in each array corresponds to a single logical entity.
T/F: Parallel arrays are a good choice when you need to store complex objects with multiple attributes.
T/F: Parallel arrays are automatically sorted and searchable.
T/F: Parallel arrays are a type of multidimensional array.
COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark