Questions and Answers
- What do all STL containers define?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
All the STL containers define the iterator types for that container, e.g., iterator and const_iterator, e.g., vector::iterator and the begin/end methods for that container, e.g., begin() and end().
- What is the output of this program?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
multimap<char, int> MultimapData;
MultimapData.insert(make_pair('Q', 105));
MultimapData.insert(make_pair('Q', 250));
MultimapData.insert(make_pair('Q', 120));
MultimapData.insert(make_pair('Q', 102));
MultimapData.insert(make_pair('Q', 220));
pair<char, int> highest = *MultimapData.rbegin();
multimap<char, int> :: iterator Iter = MultimapData.begin();
do
{
cout << (*Iter).first << " => " << (*Iter).second << '\n';
} while ( MultimapData.value_comp()(*Iter++, highest) );
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, the method rbegin is used to return the first element in the map.
- What is the output of this program?
#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue<int> QueueData;
QueueData.push(12);
QueueData.push(25);
QueueData.push(13);
cout << QueueData.top() << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
In this program, We used the queue template and the top method is used to retain the last but before element.
- What is the output of this program?
#include <iostream>
#include <map>
using namespace std;
int main ()
{
multimap<char, int> MultimapData;
MultimapData.insert(make_pair('P', 150));
MultimapData.insert(make_pair('Q', 250));
MultimapData.insert(make_pair('Q', 300));
MultimapData.insert(make_pair('R', 450));
cout << MultimapData.size() << '\n';
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We are counting the number of elements in the map.
- What is the lifetime of the element in container?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
A Container “owns” its elements: the lifetime of an element stored in a container cannot exceed that of the Container itself.