C++ Institute C++ Certified Professional Programmer CPP Question # 38 Topic 4 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 38 Topic 4 Discussion

CPP Exam Topic 4 Question 38 Discussion:
Question #: 38
Topic #: 4

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

#include

#include

#include <algorithm>

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(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.