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 4 Question 72 Discussion

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

What happens when you attempt to compile and run the following code? Choose all possible answers.

#include

using namespace std;

class C {

public:

int _c;

C():_c(0){}

C(int c) { _c = c;}

C operator+=(C & b) {

C tmp; tmp._c = _c+b._c;

return tmp;

} };

ostream & operator<<(ostream & c, const C & v) {

c<

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

T getV() { return _v; }

void add(T & a) { _v+=a; }

};

int main()

{

A b(2);

Aa (5);

a.add(C());

cout << a.getV() <

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Mertie
2 days ago
The program will compile and run, but I'm not sure about the output. The default constructor for C adds 0 to the member variable _c, so I'm curious to see what the final value will be.
upvoted 0 times
...
Tesha
9 days ago
I'm not sure. I think the program will cause a runtime exception because there might be an issue with the way the operator+= is implemented in class C.
upvoted 0 times
...
Ciara
10 days ago
I agree with Jeniffer. The program should compile and run without any issues since the operator+= is defined for class C.
upvoted 0 times
...
Jeniffer
16 days ago
I think the program will display:5 because the code seems to be adding a default constructed object of class C to the object a.
upvoted 0 times
...

Save Cancel