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 CPA-21-02 Exam - Topic 7 Question 56 Discussion

What is the output of the program?#include #include using namespace std;int main () {string s1 = "Hello", s2 = "World";s2 = s1 + s2;cout
B) It prints: HelloWorld
A) It prints: Hello
C) It prints: WorldHello
D) It prints: WorldHelloWorld

C++ Institute CPA-21-02 Exam - Topic 7 Question 56 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 56
Topic #: 7
[All CPA-21-02 Questions]

What is the output of the program?

#include

#include

using namespace std;

int main () {

string s1 = "Hello", s2 = "World";

s2 = s1 + s2;

cout << s2;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Francesco
28 days ago
So, B is the correct answer, right?
upvoted 0 times
...
Pedro
1 month ago
Exactly! "Hello" comes first.
upvoted 0 times
...
Carole
1 month ago
The output combines both strings.
upvoted 0 times
...
Francesco
1 month ago
I feel confused, but I agree with Carole.
upvoted 0 times
...
Pedro
2 months ago
Yeah, because s2 is assigned s1 + s2.
upvoted 0 times
...
Carole
2 months ago
I think it prints: HelloWorld.
upvoted 0 times
...
Sheridan
2 months ago
Just a simple string concatenation, nothing surprising here.
upvoted 0 times
...
Hillary
2 months ago
That's interesting, I didn't expect that output!
upvoted 0 times
...
My
2 months ago
Wait, are you sure? I thought it would be option C.
upvoted 0 times
...
Dustin
2 months ago
Totally agree, option B is correct!
upvoted 0 times
...
Gary
3 months ago
It prints: HelloWorld
upvoted 0 times
...
Mitzie
3 months ago
I practiced a question like this before, and I believe it concatenates the strings in the order they are written, so it should be "HelloWorld".
upvoted 0 times
...
Cassie
3 months ago
I feel like it could be "WorldHello" because s2 was originally "World" and then modified, but I’m confused about the order.
upvoted 0 times
...
Jame
3 months ago
I'm not entirely sure, but I remember something similar where string concatenation was involved. I think it might be option B.
upvoted 0 times
...
Stanford
3 months ago
I think the output will be "HelloWorld" since s2 is assigned the value of s1 + s2.
upvoted 0 times
...

Save Cancel