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

Last Updated on June 24, 2022 by Admin

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

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
void 
myprint (pair < int, int > i)
{
     cout << i.first <<", ";  
}
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];    //LINE I
     }
   for_each(m.begin (), m.end(), myprint);   //LINE II
   return 0;
}
  • compilation error in LINE II
  • size of the map is 8
  • size of the map is 6
  • the program outputs 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  • size of the map is 7
  • the program outputs 0
  • the compilation will be thrown at LINE I
  • the compilation will be thrown at LINE II 
  • the program outputs 0, 1, 2, 3, 4, 5, 9,
  • the program outputs 0, 1, 2, 3, 4, 5, 6,
5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments