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

Actual exam question for C++ Institute's CPP exam
Question #: 89
Topic #: 7
[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 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
4 months 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
4 months 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
3 months ago
Yes, the code adds 1 to each element, so the output should be 2 3 4 5 6 7 8 9 10 11.
upvoted 0 times
...
Lore
4 months ago
I think the answer is B.
upvoted 0 times
...
...
Miesha
4 months 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
4 months 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
3 months ago
I agree with you, it's E. There seems to be a compilation error with the bind1st function.
upvoted 0 times
...
Mammie
3 months ago
I think it might be D.
upvoted 0 times
...
Mabel
3 months ago
I'm going with C.
upvoted 0 times
...
Fletcher
4 months ago
No way, it's definitely B. The Add function is adding 1 to each element in the vector.
upvoted 0 times
...
Cecil
4 months ago
I believe it's B.
upvoted 0 times
...
Fletcher
4 months ago
I think it's actually D. The code seems to be adding elements in reverse order.
upvoted 0 times
...
Yan
4 months ago
I think the answer is A.
upvoted 0 times
...
...
Isaiah
4 months ago
I think the answer is D) 11 10 9 8 7 6 5 4 3 2
upvoted 0 times
...
Patrick
5 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
4 months ago
Let's see the correct answer.
upvoted 0 times
...
Shawnee
4 months ago
I agree with User1, I also think it's B.
upvoted 0 times
...
Dorian
4 months ago
I'm not sure, but I think it might be E.
upvoted 0 times
...
Azzie
5 months ago
I think the answer is B.
upvoted 0 times
...
...
Latonia
5 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
5 months ago
I disagree, I believe the answer is E) compilation error
upvoted 0 times
...
Lashonda
5 months ago
I think the answer is B) 2 3 4 5 6 7 8 9 10 11
upvoted 0 times
...

Save Cancel