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
Sheridan
5 days ago
Just a simple string concatenation, nothing surprising here.
upvoted 0 times
...
Hillary
10 days ago
That's interesting, I didn't expect that output!
upvoted 0 times
...
My
15 days ago
Wait, are you sure? I thought it would be option C.
upvoted 0 times
...
Dustin
20 days ago
Totally agree, option B is correct!
upvoted 0 times
...
Gary
25 days ago
It prints: HelloWorld
upvoted 0 times
...
Mitzie
1 month 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
1 month 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
1 month 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
2 months ago
I think the output will be "HelloWorld" since s2 is assigned the value of s1 + s2.
upvoted 0 times
...

Save Cancel