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) <string>
b) <regex>
c) <ios>
d) <reg>
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: Vector in the container library contains sequence container that manipulates and encapsulates dynamic size arrays.
4. What will be the output of the following C++ code?
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
v.assign( 10, 42 );
for (int i = 0; i < v.size(); i++)
{
cout << v[i] << " ";
}
}
a) 42
b) 42 42
c) 424
d) 42 for 10 times
View Answer
Explanation: 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?
#include <iostream>
#include <list>
#include <queue>
using namespace std;
int main()
{
queue<char> q;
q.push('a');
q.push('b');
q.push('c');
cout << q.front();
q.pop();
cout << q.front();
q.pop();
cout << q.front();
q.pop();
}
a) ab
b) abc
c) a
d) error
View Answer
Explanation: 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?
#include <list>
#include <string>
#include <iostream>
using namespace std ;
typedef list<string> LISTSTR;
int main()
{
LISTSTR :: iterator i;
LISTSTR test;
test.insert(test.end(), "one");
test.insert(test.end(), "two");
LISTSTR test2(test);
LISTSTR test3(3, "three");
LISTSTR test4(++test3.begin(),
test3.end());
cout << "test:";
for (i = test.begin(); i != test.end(); ++i)
cout << " " << *i << endl;
cout << "test:";
for (i = test2.begin(); i != test2.end(); ++i)
cout << " " << *i << endl;
cout << "test:";
for (i = test3.begin(); i != test3.end(); ++i)
cout << " " << *i << endl;
cout << "test:";
for (i = test4.begin(); i != test4.end(); ++i)
cout << " " << *i << endl;
}
a) test
b) test one
c) test two
d)
test: one two test: one two test: three three three test: three threeView Answer
Explanation: 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) <algorithm>
b) <containers>
c) <iterators>
d) <process>
View Answer
Explanation: There is no header file named <process> 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
View Answer
Explanation: 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
View Answer
Explanation: count is used to return the new number of buckets.
10. What is the use of <exception> 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
View Answer
Explanation: <exception> header file contains standard exception files used for exception handling in a C++ program.
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]
- Apply for C++ Internship
- Check Computer Science Books
- Check C++ Books
- Practice Programming MCQs
- Apply for Computer Science Internship