New Year Sale ! 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
2 months ago
Dude, what is this 'bind1st' nonsense? Is this some kind of advanced C++ voodoo magic or something?
upvoted 0 times
Joseph
13 days ago
User 1
upvoted 0 times
...
Haydee
15 days ago
User 2
upvoted 0 times
...
Erinn
25 days ago
User 1
upvoted 0 times
...
...
Stevie
2 months 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
Glory
25 days ago
Let's try compiling it to see what happens.
upvoted 0 times
...
Gennie
1 months ago
I'm not sure, maybe it's option E) compilation error.
upvoted 0 times
...
Fletcher
1 months ago
Yeah, that bind1st part seems off.
upvoted 0 times
...
Wade
1 months ago
I think it's a compilation error too.
upvoted 0 times
...
...
Kanisha
2 months ago
Haha, the correct answer is obviously C. Gotta love that reverse iteration, it's a classic.
upvoted 0 times
Adolph
22 days ago
Actually, the correct answer is C) 10 9 8 7 6 5 4 3 2 1
upvoted 0 times
...
Roselle
28 days ago
Nope, it's E) compilation error
upvoted 0 times
...
Lakeesha
29 days ago
I think it's actually A) 1 2 3 4 5 6 7 8 9 10
upvoted 0 times
...
Adolph
1 months ago
Definitely, reverse iteration is always fun!
upvoted 0 times
...
...
Maxima
2 months ago
Wait, why are we reversing the order of the elements? Shouldn't the output be the original array?
upvoted 0 times
Katie
30 days ago
User 1
upvoted 0 times
...
Jacquline
1 months ago
User 1
upvoted 0 times
...
Tamesha
1 months ago
User 2
upvoted 0 times
...
Zona
1 months ago
User 2
upvoted 0 times
...
Goldie
1 months ago
User 1
upvoted 0 times
...
Quentin
2 months ago
User 1
upvoted 0 times
...
...
Nydia
3 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
2 months ago
I think you're right, option B does seem like the most logical choice.
upvoted 0 times
...
Cecil
2 months ago
B) 2 3 4 5 6 7 8 9 10 11
upvoted 0 times
...
...
Tina
3 months ago
I disagree, I believe the correct answer is E) compilation error.
upvoted 0 times
...
Catalina
3 months ago
I think the answer is B) 2 3 4 5 6 7 8 9 10 11.
upvoted 0 times
...

Save Cancel