Module 6 - Questions

Arrays:

  1. What is an array, and why is it important in programming?

  2. How can you create and initialize an array in your programs?

  3. What are some common mistakes that programmers make when working with arrays, and how can they be avoided?

  4. How can you use arrays to store and manipulate large sets of related data in your programs?

  5. What are multi-dimensional arrays, and how can you use them to store and manipulate more complex data structures?

  6. What is the purpose of a parallel array?

  7. How can you optimize the performance of your programs by using arrays efficiently?

  8. How can you use arrays to solve real-world problems in your programming projects?

Array Multiple Choice Questions

  1. What is the index of the first element in a C++ array?

    • [ ] 1

    • [ ] 0

    • [ ] -1

    • [ ] Undefined

  2. 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;

  3. 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);

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

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

  1. T/F: Arrays in C++ are dynamic, meaning they can be resized during runtime.

  2. T/F: The elements of an array in C++ are stored in contiguous memory locations.

  3. T/F: You can declare an array without specifying its size if you initialize it at the time of declaration.

  4. T/F: C++ arrays perform bounds checking when accessing elements.

  5. T/F: It is possible to have arrays of any data type, including user-defined types.

Vector Multiple Choice Questions

  1. Which header file must be included to use vectors in C++?

    • [ ] <array>

    • [ ] <vector>

    • [ ] <list>

    • [ ] <deque>

  2. How do you declare an empty vector of integers?

    • [ ] vector<int> vec;

    • [ ] int vector vec;

    • [ ] vector vec<int>;

    • [ ] int vec[];

  3. Which member function is used to add an element at the end of a vector?

    • [ ] push()

    • [ ] append()

    • [ ] add()

    • [ ] push_back()

  4. Which of the following is NOT a member function of the vector class?

    • [ ] size()

    • [ ] pop_back()

    • [ ] clear()

    • [ ] get()

True or False Questions

  1. T/F: Vectors in C++ are dynamic arrays that can grow or shrink at runtime.

  2. T/F: Elements in a vector are stored in non-contiguous memory locations.

  3. T/F: It is mandatory to specify the size of a vector at the time of its declaration.

  4. T/F: You can use array-style indexing to access elements in a vector.

Parallel Array Multiple Choice Questions

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

  2. What is the primary advantage of using parallel arrays?

    • [ ] Dynamic resizing

    • [ ] Type safety

    • [ ] Memory efficiency

    • [ ] Built-in sorting and searching

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

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

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

  1. T/F: Parallel arrays are a feature built into the C++ language.

  2. T/F: In parallel arrays, the element at a given index in each array corresponds to a single logical entity.

  3. T/F: Parallel arrays are a good choice when you need to store complex objects with multiple attributes.

  4. T/F: Parallel arrays are automatically sorted and searchable.

  5. T/F: Parallel arrays are a type of multidimensional array.

 

COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark