BlackFriday 2024! 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 5 Question 83 Discussion

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

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

#include

#include

#include

using namespace std;

void print(int v) { cout<

struct Sequence {

int start;

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

int operator()() {

return 10*(1+(start++ %3));

}

};

int main() {

vector v1(10);

generate_n(v1.begin(), 10, Sequence(1));

remove(v1.begin(), v1.end(), 10);

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

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Kristeen
5 months ago
Hmm, valid point Eve, 'remove' here doesn't shrink the vector. C might still be correct.
upvoted 0 times
...
Ettie
5 months ago
I feel like it could be D since 'remove' might not work correctly here.
upvoted 0 times
...
Maynard
5 months ago
Good point, Maybe that's why Option B could make sense.
upvoted 0 times
...
Rodolfo
6 months ago
But doesn't 'remove' modify the sequence? Might break the expected output.
upvoted 0 times
...
Polly
6 months ago
I think the answer is C. The sequence seems to increment and wrap.
upvoted 0 times
...
Mabel
6 months ago
I'm not sure about this question. Seems tricky.
upvoted 0 times
...

Save Cancel