Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 9 Question 109 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 109
Topic #: 9
[All CPP Questions]

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

#include

#include

#include

using namespace std;

class B { int val;

public:

B(int v):val(v){}

int getV() const {return val;} bool operator < (const B & v) const { return val

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

B t1[]={3,2,4,1,5};

B t2[]={5,6,8,2,1};

vector v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

set_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin());

for_each(v1.begin(), v1.end(), Out(cout));cout<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Kristofer
3 days ago
I think the answer is A because set_symmetric_difference will give the elements that are in one of the ranges but not in both.
upvoted 0 times
...
Bonita
5 days ago
Wait, did they just try to use a vector with a custom class? Sounds like a recipe for a good ol' fashioned compilation error to me.
upvoted 0 times
...
Denise
6 days ago
Oh man, this code looks like a real head-scratcher! I bet the compiler is gonna choke on it like a cat with a hairball.
upvoted 0 times
...