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 5 Question 83 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 83
Topic #: 5
[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 t1[]={1,2,3,4,5,6,7,8,9,10};

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

vector v1(t1, t1+10);

vector v2(t2, t2+10);

vector v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());

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

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Rodrigo
4 days ago
I think the answer is B) 0 1.
upvoted 0 times
...
Alva
6 days ago
Hmm, the transform() function is taking the elements of v1 and v2 in reverse order and subtracting them, storing the results in v3. The for_each() loop is then printing the elements of v3 in reverse order. I think the correct answer is C) 1 0.
upvoted 0 times
...
Dianne
7 days ago
This code looks like it's using the transform() and for_each() algorithms to perform some kind of vector manipulation. The output suggests that the transform() is subtracting the elements of the two input vectors, but I'm not sure about the details.
upvoted 0 times
...

Save Cancel