What will happen when you attempt to compile and run the following code?

Last Updated on May 22, 2022 by Admin 2

What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int 
main() {
   int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
   map < int, int > m;
   for (int i = 0; i < 7; i++)
     {
        m[i] = mynumbers[i];   
     }
   pair < const int, int > p (4, 1);
   map < int, int >::iterator it = find (m.begin (), m.end(), p);  //LINE I
   if (it != m.end())
      cout << it->first << endl;
   else
      cout << "Not found! \n";
   return 0;
}
  • the program outputs 1
  • the program outputs Not found!
  • the program outputs 4
  • the compilation will be thrown at LINE I
  • compilation error in LINE I
  • the program outputs 5
5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments