250+ TOP MCQs on Standard Library Design and Answers

This section on C++ interview questions and answers on “Standard Library Design”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ interview questions on “Standard Library Design” along with answers, explanations and/or solutions:

1. Pick out the wrong header file about strings.
a)
b)
c)
d)
Answer: c
Clarification: The standard header files for string is string and regex. So the wrong one presented here is ios.

2. Which is best for coding the standard library for c++?
a) no trailing underscores on names
b) complex objects are returned by value
c) have a member-swap()
d) all of the mentioned
Answer: d
Clarification: Best coding for the standard library for c++ is:
-> No trailing underscores on names
-> Complex objects are returned by value
-> It should have a member-swap().

3. What is meant by vector in the container library contains?
a) It is a sequence container that encapsulates dynamic size arrays
b) It is a sequence container that encapsulates static size arrays
c) It manages the memory
d) It manages the length and size
Answer: a
Clarification: Vector in the container library contains sequence container that manipulates and encapsulates dynamic size arrays.

  250+ TOP MCQs on Functors and Answers

4. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main()
  5.     {
  6.         vector<int> v;
  7.         v.assign( 10, 42 );
  8.         for (int i = 0; i < v.size(); i++) 
  9.         {
  10.             cout << v[i] << " ";
  11.         }
  12.     }

a) 42
b) 42 42
c) 424
d) 42 for 10 times
Answer: d
Clarification: In this program, We used the vector to print the 42 for 10 times.
Output:

$ g++ std.cpp
$ a.out
42 42 42 42 42 42 42 42 42 42

5. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     int main()
  6.     {
  7.         queue<char> q;
  8.         q.push('a');
  9.         q.push('b');
  10.         q.push('c');
  11.         cout << q.front();
  12.         q.pop();
  13.         cout << q.front();
  14.         q.pop();
  15.         cout << q.front();
  16.         q.pop();
  17.     }

a) ab
b) abc
c) a
d) error
Answer: b
Clarification: We are using queue in this program and queue follows FIFO strategy to handle data hence the following output pattern is observed.
Output:

$ g++ std1.cpp
$ a.out
abc

6. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std ;
  5.     typedef list<string> LISTSTR; 
  6.     int main()
  7.     {
  8.         LISTSTR :: iterator i;
  9.         LISTSTR test;
  10.         test.insert(test.end(), "one");
  11.         test.insert(test.end(), "two");
  12.         LISTSTR test2(test);
  13.         LISTSTR test3(3, "three");
  14.         LISTSTR test4(++test3.begin(),
  15.         test3.end());
  16.         cout << "test:";
  17.         for (i =  test.begin(); i != test.end(); ++i)
  18.             cout << " " << *i << endl;
  19.         cout << "test:";
  20.         for (i =  test2.begin(); i != test2.end(); ++i)
  21.             cout << " " << *i << endl;
  22.         cout << "test:";
  23.         for (i =  test3.begin(); i != test3.end(); ++i)
  24.             cout << " " << *i << endl;
  25.         cout << "test:";
  26.         for (i =  test4.begin(); i != test4.end(); ++i)
  27.             cout << " " << *i << endl;
  28.     }

a) test
b) test one
c) test two
d)

 test: one
 two
test: one
 two
test: three
 three
 three
test: three
 three

View Answer

Answer: d
Clarification: In this program, We used the list to manipulate the given value.
Output:

$ g++ std3.cpp
$ a.out
test: one
 two
test: one
 two
test: three
 three
 three
test: three
 three

 
 

7. Pick out the wrong header file.
a)
b)
c)
d) Answer: d
Clarification: There is no header file named in C++.

8. What is meant by standard c++ library?
a) It is the collection of class definitions for standard data structures and a collection of algorithms
b) It is a header file
c) Collection of algorithms
d) Step by step process
Answer: a
Clarification: It is the collection of class definitions for standard data structures. This part of the library was derived from the Standard Template Library.

9. Pick out parameter for rehash method in unordered_set in c++?
a) count
b) size
c) hash
d) type
Answer: a
Clarification: count is used to return the new number of buckets.

10. What is the use of header
a) Contains the standard exception files
b) Contains the standard library files
c) It is used to arise an exception in the program
d) Reduce the memory size
Answer: a
Clarification: header file contains standard exception files used for exception handling in a C++ program.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top