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 7 Question 89 Discussion

Actual exam question for C++ Institute's CPP - C++ Certified Professional Programmer exam
Question #: 89
Topic #: 7
[All CPP - C++ Certified Professional Programmer 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 Add {

int operator()(int & a, int & b) {

return a+b;

}

};

int main() {

int t[]={1,2,3,4,5,6,7,8,9,10};

vector v1(t, t+10);

vector v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind1st(1,Add()));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Evette
12 days ago
This is too easy! Clearly the answer is B. Who needs to read code when you can just guess the right answer?
upvoted 0 times
...
Melissa
13 days ago
Ah, I see what's going on here. The code is using a cusLeslie functor to add 1 to each element, so the answer must be B.
upvoted 0 times
Lore
4 days ago
I think the answer is B.
upvoted 0 times
...
...
Miesha
18 days ago
I'm not sure about this one. The code looks a bit complex, but I'll go with option D just to be different.
upvoted 0 times
...
Leslie
23 days ago
Ha! I bet the answer is C. Reversing the vector and printing it out seems like the obvious solution here.
upvoted 0 times
Fletcher
2 days ago
No way, it's definitely B. The Add function is adding 1 to each element in the vector.
upvoted 0 times
...
Cecil
4 days ago
I believe it's B.
upvoted 0 times
...
Fletcher
8 days ago
I think it's actually D. The code seems to be adding elements in reverse order.
upvoted 0 times
...
Yan
17 days ago
I think the answer is A.
upvoted 0 times
...
...
Isaiah
29 days ago
I think the answer is D) 11 10 9 8 7 6 5 4 3 2
upvoted 0 times
...
Patrick
1 months ago
Hmm, this looks like a tricky one. I'm going to guess option B, since the question mentions that we're trying to add 1 to each element of the vector.
upvoted 0 times
Beata
6 days ago
User2: Let's see the correct answer.
upvoted 0 times
...
Shawnee
10 days ago
User3: I agree with User1, I also think it's B.
upvoted 0 times
...
Dorian
26 days ago
User2: I'm not sure, but I think it might be E.
upvoted 0 times
...
Azzie
1 months ago
User1: I think the answer is B.
upvoted 0 times
...
...
Latonia
2 months ago
I'm not sure, but I think the correct answer is A) 1 2 3 4 5 6 7 8 9 10
upvoted 0 times
...
Olive
2 months ago
I disagree, I believe the answer is E) compilation error
upvoted 0 times
...
Lashonda
2 months ago
I think the answer is B) 2 3 4 5 6 7 8 9 10 11
upvoted 0 times
...

Save Cancel