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

Actual exam question for C++ Institute's CPP exam
Question #: 87
Topic #: 9
[All CPP 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
5 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
5 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
Jacqueline
3 months ago
I've seen worse code before. Option D does seem like the most likely outcome.
upvoted 0 times
...
Corinne
4 months ago
Yeah, the code looks a bit messy. I agree, option D seems like the correct choice.
upvoted 0 times
...
Nicolette
4 months ago
I think the code will compile but not display anything. Option D sounds right.
upvoted 0 times
...
Dean
4 months ago
Yeah, option D seems like the most likely outcome.
upvoted 0 times
...
Bettyann
4 months ago
I agree, but it might not display anything when run.
upvoted 0 times
...
Alisha
4 months ago
I think the code will compile without any errors.
upvoted 0 times
...
...
Emile
5 months ago
Hmm, looks like there's some string manipulation happening here. I'll go with option C - 'world!Hello'.
upvoted 0 times
Shelba
4 months ago
I believe it will show: world!Hello
upvoted 0 times
...
Shelba
4 months ago
I think it will display: world!Hello
upvoted 0 times
...
...
Stefany
5 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
5 months ago
I agree with Starr, A) program will display: Hello world! makes sense because of the code logic
upvoted 0 times
...
Romana
5 months ago
I disagree, I believe the answer is B) compilation error
upvoted 0 times
...
Starr
5 months ago
I think the answer is A) program will display: Hello world!
upvoted 0 times
...
Rodrigo
5 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
4 months ago
Yes, the output will be 'Hello world!'
upvoted 0 times
...
Norah
4 months ago
So, the correct answer should be option A.
upvoted 0 times
...
Denny
4 months ago
I agree, it looks like a template class implementation.
upvoted 0 times
...
Paz
5 months ago
I think the program will display: Hello world!
upvoted 0 times
...
...

Save Cancel