C++ Programming Multiple Choice Questions & Answers (MCQs) on “seq_con Array Class – 1”.
1. What is sequence container arrays?
a) C-like arrays
b) Template class sequence container, alternative for C-like arrays
c) Collection of data of the same type
d) Collection of objects
Answer: b
Clarification: Sequence Containers arrays are an alternative for C-like arrays. It is a static continuous array that uses template classes with extended features for array implementation.
2. Pick the correct statement.
a) Sequence Container arrays know (somehow stores within) its size whereas C-like arrays do not
b) Sequence Container arrays have no advantage over C-like arrays
c) Sequence Container arrays are same as C-like arrays
d) Sequence Container arrays are also present in C
Answer: a
Clarification: Sequence Containers Arrays stores its size within itself so need to pass extra size parameter when passing this array as an argument.
3. Which of the following is/are advantage(s) of Sequence Container arrays over C-like arrays?
a) Sequence Container arrays store its size within itself whereas C-like arrays do not
b) Sequence Container arrays are more efficient
c) Sequence Container arrays have no array decay problem whereas C-like arrays do have
d) All of the mentioned
Answer: d
Clarification: Sequence Container arrays(a.k.a Array classes) somehow stores its size and it can be implemented efficiently. Also, Array classes do not have Array decay problem.
4. Which of the follwoing function(s) of Array classes are similar to [] operator?
a) at()
b) get()
c) both at() and get()
d) front()
Answer: c
Clarification: Both at() and get() function are used to access the elements stored at i’th position of the array.
5. How many different ways are there to access an element of array classes at the ith position?
a) 1
b) 2
c) 3
d) 4
Answer: c
Clarification: There are three ways of accessing Array classes as mentioned below:
i. using [] operator(same as C-like arrays)
ii. using at() function available in array classes.
iii. using get() function not a member of the array class.
6. What header file is included to use array classes?
a)
b)
c)
d)
Answer: a
Clarification:
7. What is the correct syntax of declaring an array class?
a) array
b) array
c) Array
d) Array
Answer: b
Clarification: The declaration of array class starts with a keyword array followed by <> specifying the type and size of array and then the name of the identifier. Example: array
8. What will be the output of the following C++ code?
#include#include using namespace std; int main(int argc, char const *argv[]) { array<int,5> arr = {1,2,3,4,5}; cout<<"Printing Using [] operator: "; for(int i=0;i<5;i++){ cout<<arr[i]<<" "; } cout<<endl; cout<<"Printing Using at() function: "; for(int i=0;i<5;i++){ cout<<arr.at(i)<<" "; } cout<<endl; return 0; }
a)
1 2 3 4 5 1 2 3 4 5
b)
Printing Using [] operator: 1 2 3 4 5 Printing Using at() function: 1 2 3 4 5
c)
Printing Using at() function: 1 2 3 4 5 Printing Using [] operator: 1 2 3 4 5
d) Printing Using at() function: 1 2 3 4 5
Answer: b
Clarification: In this program we are trying to print the array first using [] operator then using the at() function of the array class.
Output:
$ ./a.out Printing Using [] operator: 1 2 3 4 5 Printing Using at() function: 1 2 3 4 5
