My Report

C++ STL Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

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

#include <iostream>  
#include <utility>
#include <string>

using namespace std;

int main () 
{
  pair <int,int> p1(1,2);
  pair <int,int> p2(3,4);
  cout<<"Pair(first,second) = ("<<p1.first<<","<<p1.second<<")\n";
  p1.swap(p2);
  cout<<"Pair(first,second) = ("<<p1.first<<","<<p1.second<<")\n";
  return 0;
}

2. Which of the following is correct way of copying the values of pair p1 into other pair p2?

3. Which of the following is the correct syntax of using pair p?

4. Which operator is used to access the first or second element of a pair?

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

#include <iostream>  
#include <utility>
#include <string>

using namespace std;

int main () 
{
  pair <int,int> p1(1,2);
  pair <int,int> p2(3,4);
  if(p1 <= p2)
  	cout<<"P1 is small";
  else
  	cout<<"P2 is small";
  return 0;
}

6. What happens if a pair is not initialized?

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

#include <iostream>  
#include <utility>

using namespace std;

int main () 
{
  pair p(1,2);
  cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")\n";
  return 0;
}

8. Which header file is required to use pair container in your program?

9. Which of the following is the correct syntax of accessing the second element of a pair p?

10. Which of the following is the correct syntax of accessing the first element of a pair p?

11. Which of the following Operator cannot be used with pairs?

12. Which of the following operations can be performed on a pair?

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

#include <iostream>  
#include <utility>

using namespace std;

int main () 
{
  pair <int,int>p;
  p = make_pair(1,2);
  cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")\n";
  return 0;
}

14. What is a pair?

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

#include <iostream>  
#include <utility>

using namespace std;

int main () 
{
  pair <int,int> p(1,2);
  cout<<"Pair(first,second) = ("<<p.first<<","<<p.second<<")\n";
  return 0;
}

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

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.