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

Last Updated on May 22, 2022 by Admin 3

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

#include<vector>
#include <iostream>
#include <algorithm>

using namespace std;
void
printer (int i)
{
  cout << i <<", ";
}
int 
main()
{
  int mynumbers1[] = {3, 9, 0, 2};
  int mynumbers2[] = {6, 2, 4, 5};
  vector<int> v1 (2);
  sort (mynumbers2, mynumbers2 + 4);
  sort (mynumbers1, mynumbers1 + 4);   //LINE I
  set_intersection (mynumbers1, mynumbers1 + 3,  mynumbers2,  mynumbers2 + 2, v1.begin());   //LINE II
  for_each(v1.begin(), v1.end(), printer);
  return 0;
}
  • compilation error in LINE II
  • runtime error at LINE II
  • compilation error in LINE I
  • the program outputs 2, 2, 
  • the program outputs 2, 0, 
  • the program outputs 2, 
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments