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:

Rebecka
5 days ago
I think the output will be 4 3 5 2 6 1 10 8 7 9. The for_each function is adding 1 to each element, and then the reversed for_each is printing the elements.
upvoted 0 times
...
Dulce
9 days ago
The code seems to be adding 1 to each element of the vector and then printing them in reverse order. So the output should be 10 9 8 7 6 5 4 3 2 1.
upvoted 0 times
...
Marti
14 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
15 days ago
I agree with Franklyn, the bind1st function is not correctly used, so the output should be 0 0.
upvoted 0 times
...
Franklyn
25 days ago
I think the program will output 0 0 because the bind1st function is not correctly used.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77