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 2 Question 73 Discussion

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

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

#include

#include

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

bool classifier(int v) {

return v%2==0;

}

int main() {

int t[] = { 1, 5, 2, 5, 2, 4, 4, 3, 3, 1 };

vector v1(t, t+10);

set s1(t, t+10);

replace(v1.begin(), v1.end(),classifier, 10);

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Janna
4 days ago
I'm not sure, but I think there might be a compilation error.
upvoted 0 times
...
Meghann
6 days ago
The output should be D. The replace function replaces all even numbers with 10, so the output should be 10 5 2 5 2 4 4 3 3 10.
upvoted 0 times
...
Gianna
8 days ago
I believe it will output D.
upvoted 0 times
...
Janna
12 days ago
I think the answer is B.
upvoted 0 times
...

Save Cancel