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<iostream>
#include<vector>
#include<algorithm>

using namespace std;

void
printer (int i)
{
  cout << i <<", ";
}

int
main()
{
  int mynumbers1[] = {3, 9, 0, 2};
  int mynumbers2[] = {6, 1, 4, 5};
  vector<int>v1 (12);
  vector<int>v2 (7);
  sort(mynumbers1, mynumbers1 + 4);
  copy(mynumbers1, mynumbers1 + 4, v1.begin());
  sort(mynumbers2, mynumbers2 + 4);
  copy(mynumbers2, mynumbers2 + 4, v1.begin() +5); //LINE I
  sort(v1.begin(), v1.end());
  merge(v1.begin() + 4, v1.begin() + 7, v1.begin() + 5, v1.begin() +8, v2.begin()); //LINE II
  for_each(v2.begin(), v2.end(),printer);
  return 0;
}
  • compilation error in LINE II
  • the program outputs 0, 1, 1, 2, 2, 3, 0, 
  • the program outputs 0, 0, 0, 1, 1, 2, 2, 
  • the program outputs 0, 1, 1, 2, 2, 3,
  • compilation error in LINE I
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments