Cyber Monday 2024! 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 2 Question 99 Discussion

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

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

#include

#include

#include

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

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

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Jamal
16 days ago
Dude, what is this 'bind1st' nonsense? Is this some kind of advanced C++ voodoo magic or something?
upvoted 0 times
...
Stevie
20 days ago
I'm pretty sure it's a compilation error. That bind1st thing looks like some weird syntax I've never seen before.
upvoted 0 times
Fletcher
1 days ago
Yeah, that bind1st part seems off.
upvoted 0 times
...
Wade
3 days ago
I think it's a compilation error too.
upvoted 0 times
...
...
Kanisha
26 days ago
Haha, the correct answer is obviously C. Gotta love that reverse iteration, it's a classic.
upvoted 0 times
Adolph
7 days ago
Definitely, reverse iteration is always fun!
upvoted 0 times
...
...
Maxima
1 months ago
Wait, why are we reversing the order of the elements? Shouldn't the output be the original array?
upvoted 0 times
Jacquline
4 days ago
User 1
upvoted 0 times
...
Tamesha
5 days ago
User 2
upvoted 0 times
...
Zona
6 days ago
User 2
upvoted 0 times
...
Goldie
7 days ago
User 1
upvoted 0 times
...
Quentin
30 days ago
User 1
upvoted 0 times
...
...
Nydia
2 months ago
Hmm, this seems like a tricky one. I'm gonna go with option B, that makes the most sense to me.
upvoted 0 times
Cecil
1 months ago
I think you're right, option B does seem like the most logical choice.
upvoted 0 times
...
Cecil
1 months ago
B) 2 3 4 5 6 7 8 9 10 11
upvoted 0 times
...
...
Tina
2 months ago
I disagree, I believe the correct answer is E) compilation error.
upvoted 0 times
...
Catalina
2 months ago
I think the answer is B) 2 3 4 5 6 7 8 9 10 11.
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