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 9 Question 91 Discussion

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

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

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

vector v1(t, t+10);

for_each(v1.begin(), v1.end(), bind1st(plus(), 1));

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

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Marti
3 days ago
I'm not sure about the output, but I think it might be 0 1 because of the way the bind1st function is being called.
upvoted 0 times
...
Ashlyn
4 days ago
I agree with Franklyn, the bind1st function is not correctly used, so the output should be 0 0.
upvoted 0 times
...
Franklyn
14 days ago
I think the program will output 0 0 because the bind1st function is not correctly used.
upvoted 0 times
...

Save Cancel