Cyber Monday 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 4 Question 79 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 79
Topic #: 4
[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:

Stefania
5 months ago
I believe the correct answer is D) compilation error. I don't think the remove function is being used correctly in this code.
upvoted 0 times
...
Delpha
5 months ago
I'm not so sure about that. I think the answer might be C) 20 30 20 30 20 30 20 30 10 20. It could be because of the remove function.
upvoted 0 times
...
Rossana
5 months ago
I agree with Gussie. The code generates a sequence with values 20, 30, and 10, and then removes 10 from the vector.
upvoted 0 times
...
Gussie
5 months ago
I think the correct answer is A) 20 30 10 20 30 10 20 30 10 20.
upvoted 0 times
...
Karan
6 months ago
Hmm, I see your point. I might have to reconsider my answer.
upvoted 0 times
...
Luis
6 months ago
I'm with Sabrina on this one, the answer should be C.
upvoted 0 times
...
Sabrina
6 months ago
Because the remove function removes elements with the specific value of 10 in the vector.
upvoted 0 times
...
Karan
7 months ago
But why do you think that?
upvoted 0 times
...
Sabrina
7 months ago
I disagree, I believe the correct answer is C.
upvoted 0 times
...
Karan
7 months ago
I think the answer is A.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77