C++ Programming Questions and Answers – Standard Template Library

This set of C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “Standard Template Library”.

1. What is the Standard Template Library?
a) Set of C++ template classes to provide common programming data structures and functions
b) Set of C++ classes
c) Set of Template functions used for easy data structures implementation
d) Set of Template data structures only
View Answer

Answer: a
Explanation: STL expanded as Standard Template Library is set of C++ template classes to provide common programming data structures and functions.

2. Pick the correct statement.
a) STL is a generalized library
b) Components of STL are parameterized
c) STL uses the concept of templates classes and functions to achieve generalized implementation
d) All of the mentioned
View Answer

Answer: d
Explanation: STL is a generalized library and components of STL are parameterized. STL uses the concept of templates classes and function to achieve generalized implementation.

3. How many components STL has?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: STL has four components namely Algorithms, Containers, Functors and Iterators.
advertisement
advertisement

4. What are the containers?
a) Containers store objects and data
b) Containers stores all the algorithms
c) Containers contain overloaded functions
d) Containers contain set of Iterators
View Answer

Answer: a
Explanation: Containers is a component of STL which stores objects and data.

5. In how many categories, containers are divided?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: Containers are divided into 4 categories namely Sequence Containers, Associative Containers, Unordered Associative Containers and Container Adaptors.

6. What are the Sequence Containers?
a) Containers that implements data structures which can be accessed sequentially
b) Containers that implements sorted data structures for fast search in O(logn)
c) Containers that implements unsorted(hashed) data structures for quick search in O(1)
d) Containers that implements data structures which can be accessed non-sequentially
View Answer

Answer: a
Explanation: Sequence Containers is the subset of Containers that implements data structures which can be accessed sequentially.

7. How many Sequence Containers are provided by C++?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: d
Explanation: C++ provides 5 types of Sequence Containers namely array, vector, deque, forward_list and list.
advertisement

8. What are the Associative Containers?
a) Containers that implements data structures which can be accessed sequentially
b) Containers that implements sorted data structures for fast search in O(logn)
c) Containers that implements unsorted(hashed) data structures for quick search in O(1)
d) Containers that implements data structures which can be accessed non-sequentially
View Answer

Answer: b
Explanation: Associative Containers is the subset of Containers that implements sorted data structures for fast search in O(logn).

9. How many Associative Containers are provided by C++?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: c
Explanation: C++ provides 4 types of Associative Containers namely Set, Map, multiset and multimap.
advertisement

10. What are Unordered Associative Containers?
a) Containers that implements data structures which can be accessed sequentially
b) Containers that implements sorted data structures for fast search in O(logn)
c) Containers that implements unsorted(hashed) data structures for quick search in O(1)
d) Containers that implements data structures which can be accessed non-sequentially
View Answer

Answer: c
Explanation: Unordered Associative Containers is the subset of Containers that implements unsorted(hashed) data structures for quick search in O(1) amortized O(n) Worst case complexity.

11. What are Container Adaptors?
a) Containers that implements data structures which can be accessed sequentially
b) Containers that implements sorted data structures for fast search in O(logn)
c) Containers that implements unsorted(hashed) data structures for quick search in O(1)
d) Containers that provide a different interface for sequential containers
View Answer

Answer: d
Explanation: Container Adaptors is the subset of Containers that provides a different interface for sequential containers.

12. How many Container Adaptors are provided by C++?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: b
Explanation: C++ provides 3 types of Container Adaptors namely Stack, Queue and Priority Queues.

13. What are Iterators?
a) Iterators are used to iterate over C-like arrays
b) Iterators are used to iterate over pointers
c) Iterators are used to point memory addresses of STL containers
d) Iterators are used to iterate over functions
View Answer

Answer: c
Explanation: In C++, Iterators are provided to iterate over the STL containers.

14. How many types of Iterators are provided by C++?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: d
Explanation: There are five types of Iterators provided by C++ namely Input Iterators, Output Iterators, Forward Iterators, Bi-directional Iterators and Random-access Iterators.

15. Which header file is used for Iterators?
a) <iterator>
b) <algorithm>
c) <iter>
d) <loopIter>
View Answer

Answer: a
Explanation: Iterators are present inside the <iterator> header file so this header file is needed to use Iterators.

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.