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 <set> #include <vector> using namespace std; template <class T>void print (T start, T end) { while(start != end) { std::cout << *start << ", "; start++; } } int main() { int mynumbers[] = { 8, 6, 4, 1}; vector <int> v (mynumbers, mynumbers + 6); set <int> s (v.begin(), v.end()); for(int i = 4; i > 0; i) { int x = *(s.begin()); //LINE I s.pop(); //LINE II v.push_back(i + x); } print(v.begin(), v.end()); print(s.begin(), s.end()); cout << endl; return 0; }
- program outputs:
8, 6, 4, 1, 8, 6, 4, 1,
- program outputs:
8, 6, 4, 1,
- runtime error at LINE I
- compilation error in LINE II
- compilation error in LINE I
- program outputs:
8, 6, 4, 1, 1, 4, 6, 8