Sequential data structures in C++ allow developers to store and manipulate contiguous collections of elements in memory. C++ provides multiple approaches to handling lists of items: traditional fixed-size C-style arrays, modern type-safe std::array wrappers from C++11, and dynamic, auto-resizing std::vector sequence containers. Understanding how arrays interact with raw memory requires mastery over array decay (where an array degrades to a pointer to its first element), pointer arithmetic, zero-initialization behavior, multi-dimensional layout, and heap-allocated memory management via new[] and delete[].
C++ Arrays / Lists - MCQs
1 min read
Correct Answer: b) A collection of elements of the same type placed in contiguous memory locations
Explanation:
In C++, a standard array is a fixed-size sequence of elements of the same data type stored in contiguous memory blocks.
Correct Answer: b) int arr[5];
Explanation:
The syntax to declare a built-in array in C++ is type name[size]; therefore, int arr[5]; is the correct declaration.
Correct Answer: b) 0
Explanation:
Arrays in C++ are zero-indexed, meaning the first element is accessed using the index 0.
Correct Answer: c) It results in undefined behavior
Explanation:
C++ does not perform bounds checking on built-in arrays. Accessing memory outside the array bounds leads to undefined behavior, which may cause crashes or data corruption.
Correct Answer: a) int arr[5] = {0};
Explanation:
Initializing an array with {0} sets the first element to 0 and value-initializes the rest to 0 as well.
Correct Answer: b) sizeof(arr) / sizeof(arr[0])
Explanation:
For a statically allocated array, sizeof(arr) gives the total bytes, and dividing by sizeof(arr[0]) gives the total number of elements.
Correct Answer: b) A pointer to the first element of the array
Explanation:
By default, an array decays into a pointer pointing to its first element when passed as an argument to a function.
Correct Answer: a) The size must be a constant expression evaluated at compile time
Explanation:
For statically allocated arrays in C++, the array size must be a compile-time constant expression.
Correct Answer: b) The size of the pointer itself (e.g., 4 or 8 bytes)
Explanation:
When sizeof() is applied to a pointer, it returns the size of the pointer, not the memory dynamically allocated to it.
Correct Answer: b) Declares an array of size 3 initialized with 1, 2, and 3
Explanation:
If the size is omitted, the compiler deduces the size of the array based on the number of elements in the initializer list.
Correct Answer: b) arr[2]
Explanation:
Because arrays are zero-indexed, the first element is at index 0, the second at 1, and the third at index 2.
Correct Answer: a) The process of an array losing its size information when passed to a function
Explanation:
Array decay occurs when an array type implicitly converts to a pointer to its first element, losing its length information.
Correct Answer: b) int* arr = new int[10];
Explanation:
The 'new' operator followed by the type and size in square brackets is used to allocate a dynamic array.
Correct Answer: b) delete[] arr;
Explanation:
Dynamic arrays allocated with new[] must be deallocated using delete[] to ensure proper destruction and memory release.
Correct Answer: b) The number of columns
Explanation:
In a 2D array declaration type name[rows][columns], the second dimension specifies the number of columns.
Correct Answer: b) Row-major order
Explanation:
C++ stores multidimensional arrays in row-major order, meaning elements of the same row are stored contiguously in memory.
Correct Answer: c)
Explanation:
The std::array container is defined in the header file.
Correct Answer: b) It supports assignment semantics and knows its own size
Explanation:
std::array provides a member function size() and does not decay to a pointer, making it safer. It also supports direct assignment.
Correct Answer: b) std::array<int, 5> arr;
Explanation:
The syntax for std::array specifies the type followed by the constant size inside the template brackets: std::array.
Correct Answer: b) at()
Explanation:
The at() function performs bounds checking and throws a std::out_of_range exception if the index is invalid. operator[] does not check bounds.
Correct Answer: b) A reference to the first element
Explanation:
The front() method returns a reference to the first element in the container (array, list, vector, etc.).
Correct Answer: c) std::list
Explanation:
std::list is implemented as a doubly linked list, allowing fast insertions and deletions from anywhere in the container.
Correct Answer: b)
Explanation:
To use the std::list container in C++, the header must be included.
Correct Answer: b) Inserting an element in the middle (if an iterator is provided)
Explanation:
Inserting an element into a list with a known iterator takes O(1) time since it only involves changing pointers, whereas a vector requires shifting elements, taking O(N) time.
Correct Answer: c) No, it does not support random access
Explanation:
std::list does not support random access (operator[]) because finding an element requires traversing the list from the beginning or end.
Correct Answer: d) std::forward_list
Explanation:
std::forward_list (introduced in C++11) is implemented as a singly linked list, which is more memory efficient than std::list.
Correct Answer: c) It has lower memory overhead per node
Explanation:
std::forward_list uses only one pointer (next) per node instead of two (prev and next) used by std::list, thus saving memory.
Correct Answer: b) push_back()
Explanation:
std::forward_list does not have push_back() or back() because traversing to the end of a singly linked list to append takes O(N) time without a tail pointer.
Correct Answer: b) insert_after()
Explanation:
Because a singly linked list only has forward pointers, inserting at a position requires knowing the previous node, so insert_after() is used instead of insert().
Correct Answer: c) clear()
Explanation:
The clear() method is standard across STL containers for removing all elements.
Correct Answer: b) Checks if the list has no elements
Explanation:
The empty() function returns a boolean true if the container is empty, and false otherwise.
Correct Answer: c) Using the merge() method
Explanation:
The merge() method merges another sorted list into the calling list, resulting in a single sorted list. The elements from the argument list are moved, not copied.
Correct Answer: b) It transfers elements from one list to another without copying or allocating new memory
Explanation:
splice() moves elements between lists by just relinking pointers, making it an O(1) operation (for moving specific elements) without any memory allocation.
Correct Answer: b) Bidirectional iterators
Explanation:
Because it is a doubly linked list, std::list provides bidirectional iterators allowing iteration forward and backward, but not random access.
Correct Answer: c) Forward iterators
Explanation:
std::forward_list only supports iterating sequentially from the beginning to the end, thus providing forward iterators.
Correct Answer: b) Removes all occurrences of val
Explanation:
The remove() function scans the entire list and removes all elements that match the given value.
Correct Answer: b) Using list.sort()
Explanation:
std::sort requires random access iterators, which std::list does not have. Therefore, std::list provides its own member function sort().
Correct Answer: c) O(1)
Explanation:
Since C++11, the standard mandates that std::list::size() must have a constant time complexity, O(1), by maintaining an internal size counter.
Correct Answer: c) No, it does not provide a size() method
Explanation:
std::forward_list deliberately omits the size() method to avoid the overhead of storing a size counter, ensuring it remains as lightweight as a raw C singly linked list.
Correct Answer: a) std::distance(flist.begin(), flist.end())
Explanation:
You can use std::distance() from the header to count the elements, though it will take O(N) time.
Correct Answer: b) Reverses the order of the elements in the list
Explanation:
The reverse() member function flips the sequence of elements in the list.
Correct Answer: c) unique()
Explanation:
The unique() function in std::list removes consecutive duplicate elements, leaving only the first of each.
Correct Answer: b) Call sort()
Explanation:
unique() only removes *adjacent* duplicates. To remove all duplicates, the list must be sorted first so all identical elements are adjacent.
Correct Answer: d) No iterators are invalidated
Explanation:
Unlike vectors, inserting into a list only involves updating pointers. Existing nodes stay at their memory addresses, so iterators remain valid.
Correct Answer: a) Only the iterator pointing to the erased element is invalidated
Explanation:
Erasing a node frees that node's memory. Iterators pointing to other nodes are entirely unaffected.
Correct Answer: b) int arr2D = new int*[rows]; for(int i=0; i<rows; ++i) arr2D[i] = new int[cols];
Explanation:
A dynamic 2D array is typically created as an array of pointers, where each pointer is initialized with a dynamically allocated row array.
Correct Answer: c) All dimensions except the first
Explanation:
The compiler needs to know the sizes of all secondary dimensions to calculate pointer offsets properly (e.g., void func(int arr[][4])). The first dimension can be omitted.
Correct Answer: a) data()
Explanation:
The data() method returns a direct pointer to the memory array used internally by std::array.
Correct Answer: c) They contain indeterminate (garbage) values
Explanation:
Like C-style arrays, an uninitialized std::array of built-in types contains garbage values if declared in a local scope without an initializer.
Correct Answer: a) std::array<int, 5> arr = {0};
Explanation:
Using aggregate initialization like {0} or {} will zero-initialize all elements in the std::array.
Correct Answer: b) fill()
Explanation:
The fill() member function assigns the given value to all elements in a std::array. std::list uses assign() for a similar purpose.
Correct Answer: b) Contiguous memory layout
Explanation:
Because array elements are in contiguous memory, inserting at the beginning requires shifting all existing elements, taking O(N) time.
Correct Answer: c) O(1)
Explanation:
Lists manipulate pointers to add elements, making push_front() an O(1) constant time operation.
Correct Answer: c) std::array
Explanation:
Because std::array stores data contiguously, iterating over it is highly cache-friendly and faster than chasing pointers in a list.
Correct Answer: b) int (*arr)[10];
Explanation:
int (*arr)[10] declares a pointer to an array of 10 integers. Parentheses are needed because [] has higher precedence than *.
Correct Answer: c) 30
Explanation:
arr decays to a pointer to the first element. arr + 2 points to the third element (index 2). Dereferencing it yields 30.
Correct Answer: c) std::copy(A, A + size, B);
Explanation:
C-style arrays do not support direct assignment. You must loop or use a function like std::copy to transfer elements.
Correct Answer: a) B = A;
Explanation:
Unlike C-arrays, std::array objects can be directly assigned to one another using the assignment operator if they have the same size and type.
Correct Answer: c) It causes undefined behavior
Explanation:
Calling pop_back() or pop_front() on an empty list results in undefined behavior. You should always check if it is empty() first.
Correct Answer: b) size_t (or size_type)
Explanation:
Container size methods in the STL return size_type, which is typically an unsigned integer type like size_t.
Correct Answer: a) std::list::iterator it;
Explanation:
The iterator is a nested type within the container template, so the correct syntax is Container::iterator.
Correct Answer: c) for(auto& val : list) { ... }
Explanation:
The range-based for loop (introduced in C++11) is the safest and most readable way to traverse containers.
Correct Answer: c) The last element
Explanation:
rbegin() returns a reverse iterator pointing to the very last element of the container, while rend() points to one before the first.
Correct Answer: b) It moves the iterator to the next node in the list
Explanation:
Incrementing a list iterator traverses the linked list by following the 'next' pointer to the subsequent node.
Correct Answer: b) Yes, but it will be highly inefficient (O(N) time)
Explanation:
std::binary_search accepts forward iterators, so it compiles. However, because lists lack random access, traversing to the middle elements takes linear time, destroying the performance benefit of binary search.
Correct Answer: b) std::array or std::vector
Explanation:
std::array and std::vector provide O(1) random access, whereas lists require O(N) traversal.
Correct Answer: b) remove_if()
Explanation:
remove_if() takes a predicate (a function returning true/false) and removes every element for which the predicate returns true.
Correct Answer: c) 4
Explanation:
arr[1][0] accesses the second row (index 1) and the first column (index 0), which is 4.
Correct Answer: c) The dereference (*) operator
Explanation:
Because arrays decay to pointers, the dereference operator (*) is used to access the values at the memory addresses the pointers point to.
Correct Answer: c) std::list merely adjusts a few pointers, while std::array requires shifting all subsequent elements
Explanation:
List insertion is O(1) after the position is found because it only involves rewiring node pointers. (Finding the position takes O(N), though).
Correct Answer: c) A reference to the newly inserted element (in C++17)
Explanation:
Since C++17, emplace_back() returns a reference to the newly constructed object. Prior to C++17, it returned void.
Correct Answer: b) emplace_back() constructs the element in-place, avoiding a temporary copy/move
Explanation:
emplace_back takes constructor arguments and builds the object directly in the node's memory space, which can be more efficient than creating a temporary object and copying/moving it with push_back.
Correct Answer: a) Data, a pointer to the next node, and a pointer to the previous node
Explanation:
As a doubly linked list, each node in a std::list holds the element's value along with pointers to both the successor and predecessor nodes.
Correct Answer: a) Yes, std::array<int, 0> is valid in C++
Explanation:
std::array is explicitly supported by the standard. Calling front() or back() on it yields undefined behavior, but size() returns 0.
Correct Answer: b) Because contiguous memory takes advantage of CPU cache prefetching
Explanation:
Arrays are cache-friendly. Modern CPUs fetch chunks of memory into cache; with contiguous memory, the next elements are already in the fast cache.
Correct Answer: b) Lack of bounds checking leading to buffer overflows
Explanation:
Because C-arrays do not check if an index is out of bounds, hackers can overwrite adjacent memory (buffer overflow), leading to severe security exploits.
Correct Answer: b) std::list has significant overhead due to storing two pointers per element
Explanation:
Every element in a std::list requires allocation for the data itself plus a forward and backward pointer, adding at least 8 to 16 bytes of overhead per integer.
Correct Answer: c) Pointers to characters (C-style strings)
Explanation:
argv is an array of pointers to characters. Each pointer points to a null-terminated C-style string representing a command-line argument.
Correct Answer: b) No, functions cannot return built-in arrays directly; they must return a pointer or a wrapper like std::array
Explanation:
C++ functions cannot return built-in array types. They must return a pointer, a struct containing an array, a std::array, or a std::vector.
Correct Answer: b) int (&arr)[5];
Explanation:
Parentheses are necessary: int (&arr)[5]. Without them, int& arr[5] implies an array of references, which is illegal in C++.
Correct Answer: c) C++ does not allow arrays of references
Explanation:
References are not objects in C++ (they have no storage identity), so you cannot create arrays of them. You can, however, use std::reference_wrapper.
Correct Answer: a) std::forward_list::iterator
Explanation:
Like other containers, the iterator is accessed via the scope of the container template: std::forward_list::iterator.
Correct Answer: c) No, it supports insert_after() instead
Explanation:
Because it only has forward pointers, it can only efficiently insert a node *after* a known node, using insert_after().
Correct Answer: b) before_begin()
Explanation:
std::forward_list provides a before_begin() iterator, which acts as a dummy node before the first element, allowing insertion at the absolute front via insert_after().
Correct Answer: b) std::swap(list1, list2);
Explanation:
std::swap (or list1.swap(list2)) swaps internal pointers to the head and tail, taking O(1) time. Assignment (list1 = list2) takes O(N) time because it copies elements.
Correct Answer: b) int* p = new int[5]{0};
Explanation:
In modern C++ (C++11 and later), you can use aggregate initialization with new[]: new int[5]{0} initializes all 5 elements to 0.
Correct Answer: c) remove_if()
Explanation:
std::list::remove_if() evaluates a unary predicate for each element and removes those for which the predicate evaluates to true.
Correct Answer: a) list.max_size()
Explanation:
All standard containers provide a max_size() method that returns the maximum number of elements the container can theoretically hold based on system architecture and allocator constraints.
Correct Answer: b) When you have frequent insertions/deletions in the middle of the container
Explanation:
Lists allow O(1) insertions and deletions anywhere (once the position iterator is known), whereas vectors require shifting elements.
Correct Answer: c)
Explanation:
The header provides a vast majority of STL functions (like find, count, copy) that operate on iterator ranges.
Correct Answer: b) 3
Explanation:
Due to pointer arithmetic properties inherited from C, arr[2] is equivalent to *(arr + 2), which is also equivalent to *(2 + arr), so 2[arr] is valid syntax and equals 3.
Correct Answer: c) Arrays decay to pointers, so modifications in the function affect the original array
Explanation:
Because a pointer to the original memory is passed, changes made using the array index inside the function modify the original elements.
Correct Answer: a) Using std::find_if()
Explanation:
std::find_if accepts the begin and end iterators along with a lambda or predicate (e.g., [](int x){ return x > 10; }) to find the element.
Correct Answer: b) No
Explanation:
Arrays of references are illegal in C++. Standard array elements must be assignable and have a size; references do not.
Correct Answer: b) Mergesort
Explanation:
Mergesort is ideal for linked lists because it can merge sublists simply by reassigning pointers without needing random access.
Correct Answer: b) std::array<int, 10>
Explanation:
std::array provides a compile-time fixed size along with the safety of member functions like at() which perform bounds checking.
Correct Answer: c) std::vector
Explanation:
std::vector allocates contiguous memory and must reallocate and copy/move when it outgrows capacity. Lists allocate single nodes as needed, and arrays cannot grow.
Correct Answer: c) A std::list::iterator
Explanation:
The 'auto' keyword deduces the type returned by mylist.begin(), which is std::list::iterator.
Correct Answer: a) erase removes by iterator position, remove removes by value match
Explanation:
erase() deletes elements at specific iterator locations, whereas remove() searches the list for a specific value and deletes all matching elements.
Correct Answer: b) Finding the number of steps (elements) between two iterators
Explanation:
std::distance calculates the number of increments needed to go from iterator 'a' to iterator 'b'.
Correct Answer: b) O(N) time
Explanation:
Because std::list iterators are bidirectional (not random access), std::distance must step through the list one by one, taking linear O(N) time.
Correct Answer: b) Yes, e.g., std::list arr[10];
Explanation:
You can declare an array of lists perfectly fine. It is often used to implement a hash table using chaining.
Correct Answer: b) arr.back()
Explanation:
The back() member function returns a reference to the last element. arr.end() returns an iterator past the end.
Correct Answer: b) 0
Explanation:
When an array is partially initialized, the remaining uninitialized elements are automatically initialized to zero.
Correct Answer: b) The local array's memory is deallocated when the function returns, causing a dangling pointer
Explanation:
Local arrays are stored on the stack and destroyed when the function ends. Returning a pointer to them yields undefined behavior upon access.
Correct Answer: c) reinterpret_cast
Explanation:
reinterpret_cast is used for low-level reinterpretation of bit patterns, such as mapping a byte array over a struct.
Correct Answer: b) One for type, one for the size
Explanation:
std::array is fixed-size at compile time. Its type signature includes both the element data type and the exact number of elements.
Correct Answer: c) std::vector
Explanation:
std::vector is optimized for O(1) amortized insertion at the end and offers fast contiguous iteration.
Correct Answer: c) *it
Explanation:
Iterators act like pointers. You dereference them using the asterisk (*) operator to access the underlying element.
Correct Answer: b) it->func()
Explanation:
The arrow operator (->) is overloaded on iterators to access members of the object being pointed to. (*it).func() is also correct but not an option.
Correct Answer: a) std::to_array (C++20)
Explanation:
Introduced in C++20, std::to_array converts a built-in array to a std::array. (Note: standard C++11 lacks a direct one-liner standard library function for this without manual copying or std::copy).
Correct Answer: b) No, because list iterators do not support subtraction
Explanation:
List iterators are bidirectional, not random-access. The subtraction operator requires random-access iterators. You must use std::distance() instead.
Correct Answer: b) It returns a const_iterator pointing to the first element
Explanation:
cbegin() strictly returns a constant iterator, ensuring the elements of the container cannot be modified through that iterator.
Correct Answer: b) Yes, by pushing at the back and popping from the front
Explanation:
A queue is FIFO (First-In-First-Out). std::list can push_back and pop_front in O(1) time, making it an acceptable underlying container for a queue.
Correct Answer: b) O(N)
Explanation:
The memory grows linearly with the number of elements N. Each element takes constant O(1) space, so N elements take O(N) space.
Correct Answer: b) 24
Explanation:
The total capacity is the product of all dimensions: 2 * 3 * 4 = 24 elements.
Correct Answer: c) std::array<std::string, 10>
Explanation:
std::array combined with std::string provides automatic memory management, deep copying, bounds safety, and rich member functions.
Correct Answer: b) The default constructor is called 10 times
Explanation:
When allocating an array of objects with new[], C++ automatically invokes the default constructor for every element in the array.
Correct Answer: c) No, it will cause a compile-time error
Explanation:
Arrays require default constructors to initialize the elements. If a default constructor doesn't exist (because only parameterized ones were defined), `new MyClass[10]` will fail to compile.
Correct Answer: a)
Explanation:
Utility functions for iterators like advance, distance, next, and prev are found in the header.
Correct Answer: b) Moves the iterator forward by 3 positions
Explanation:
std::advance modifies the iterator directly, moving it forward by the specified number of steps (or backward if negative).
Correct Answer: c) auto it = list.begin(); std::advance(it, 3);
Explanation:
Because list iterators cannot be added directly (like begin() + 3), you must use std::advance or std::next to step forward.
Related Posts

C++ Classes and Objects - MCQs
In C++, a class is a fundamental building block of Object-Oriented Programming (OOP) that acts as a user-defined blueprint for…
October 19, 2026By MCQs Generator

C++ Control Flow / If-Else MCQs Conditional Statements
Control flow statements determine the execution path of a program based on runtime conditions. In C++, decision-making relies primarily on…
October 20, 2026By MCQs Generator
No Image
C++ Loops (For, While)
1. What is an array in C++? a) A dynamic data structure that can change size automatically b) A collection…
October 20, 2026By MCQs Generator








