New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPP Exam - Topic 2 Question 5 Discussion

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

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

#include

#include

#include

#include

using namespace std;

class B { int val;

public:

B(int v=0):val(v){}

int getV() const {return val;}

B operator +(const B &b )const { return B(val + b.val);} };

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

template struct Add : public binary_function {

A operator() (const A & a, const A & b) const { 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(ptr_fun (Add()), 1));

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

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

0/2000 characters
Shad
4 months ago
I agree with B, looks correct to me!
upvoted 0 times
...
Walton
4 months ago
I thought it would give a compilation error, but it works!
upvoted 0 times
...
Nelida
4 months ago
Wait, how does it handle the vector size?
upvoted 0 times
...
Jerilyn
4 months ago
Definitely B! The transformation adds 1 to each element.
upvoted 0 times
...
Joseph
5 months ago
The program outputs "2 3 4 5 6 7 8 9 10 11".
upvoted 0 times
...
Marnie
5 months ago
This one seems pretty straightforward. I'm pretty sure the answer is Baiting, where the attacker leaves a tempting physical device like a USB drive to lure the victim.
upvoted 0 times
...
Elvis
5 months ago
This question seems straightforward, I think I can handle it.
upvoted 0 times
...
Avery
5 months ago
I'm not entirely confident, but I think marking the class as protected might be the best approach here. I'll double-check the question to make sure.
upvoted 0 times
...