C++ Institute C++ Certified Professional Programmer CPP Question # 27 Topic 3 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 27 Topic 3 Discussion

CPP Exam Topic 3 Question 27 Discussion:
Question #: 27
Topic #: 3

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

#include

#include

#include <algorithm>

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

struct Add : public binary_function {

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

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(Add(), 1));

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

return 0;

}

Program outputs:


A.

1 2 3 4 5 6 7 8 9 10


B.

2 3 4 5 6 7 8 9 10 11


C.

10 9 8 7 6 5 4 3 2 1


D.

11 10 9 8 7 6 5 4 3 2


E.

compilation error


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.