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 87 Discussion

Actual exam question for C++ Institute's CPP - C++ Certified Professional Programmer exam
Question #: 87
Topic #: 9
[All CPP - C++ Certified Professional Programmer Questions]

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

#include

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

void add(T & a);

void add(string & a);

};

template

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

void A::add(string & a) {

_v.insert(0, a);

}

int main()

{

Aa("Hello");

string s(" world!");

a.add(s);

cout << a.getV() <

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Regenia
1 months ago
Wait, are we supposed to actually understand this code? I'll just go with option B - 'compilation error' and call it a day.
upvoted 0 times
...
Starr
1 months ago
Haha, the programmer must have had a wild night before writing this code. Option D - 'program will run without any output' seems plausible.
upvoted 0 times
Corinne
3 days ago
Yeah, the code looks a bit messy. I agree, option D seems like the correct choice.
upvoted 0 times
...
Nicolette
10 days ago
I think the code will compile but not display anything. Option D sounds right.
upvoted 0 times
...
Dean
15 days ago
Yeah, option D seems like the most likely outcome.
upvoted 0 times
...
Bettyann
16 days ago
I agree, but it might not display anything when run.
upvoted 0 times
...
Alisha
27 days ago
I think the code will compile without any errors.
upvoted 0 times
...
...
Emile
1 months ago
Hmm, looks like there's some string manipulation happening here. I'll go with option C - 'world!Hello'.
upvoted 0 times
Shelba
25 days ago
I believe it will show: world!Hello
upvoted 0 times
...
Shelba
28 days ago
I think it will display: world!Hello
upvoted 0 times
...
...
Stefany
1 months ago
I think the answer is C) program will display: world!Hello because of the order of insertion in the code
upvoted 0 times
...
Tijuana
1 months ago
I agree with Starr, A) program will display: Hello world! makes sense because of the code logic
upvoted 0 times
...
Romana
1 months ago
I disagree, I believe the answer is B) compilation error
upvoted 0 times
...
Starr
2 months ago
I think the answer is A) program will display: Hello world!
upvoted 0 times
...
Rodrigo
2 months ago
This code looks like a template class implementation, so the correct answer should be option A. The program will display 'Hello world!'.
upvoted 0 times
Bette
14 days ago
Yes, the output will be 'Hello world!'
upvoted 0 times
...
Norah
16 days ago
So, the correct answer should be option A.
upvoted 0 times
...
Denny
17 days ago
I agree, it looks like a template class implementation.
upvoted 0 times
...
Paz
1 months ago
I think the program will display: Hello world!
upvoted 0 times
...
...

Save Cancel