Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPP Topic 6 Question 98 Discussion

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

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

void operator()(const T & val ) {

out<

}

};

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() { return start++; }

};

struct Odd { bool operator()(int v) { return v%2==0; }};

int main() {

vector v1(10);

generate(v1.begin(), v1.end(), Sequence(1));

partition(v1.begin(),v1.end(), Odd());

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

return 0;

}

Choose all possible outputs:

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Adria
1 days ago
The output should be B) 2 3 4 5 6 7 8 9 10 11. The code generates a sequence of integers starting from 1, then partitions the vector to move all even numbers to the end, and finally prints the resulting vector.
upvoted 0 times
...
Britt
2 days ago
I'm not sure, but I think the code will compile without errors.
upvoted 0 times
...
Dona
3 days ago
I believe the correct output is B) 2 3 4 5 6 7 8 9 10 11.
upvoted 0 times
...
Britt
5 days ago
I think the output will be A) 1 2 3 4 5 6 7 8 9 10.
upvoted 0 times
...

Save Cancel