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 CPA Topic 5 Question 93 Discussion

Actual exam question for C++ Institute's CPA - C++ Certified Associate Programmer exam
Question #: 93
Topic #: 5
[All CPA - C++ Certified Associate Programmer Questions]

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

#include

#include

using namespace std;

int main()

{

string s1[]= {"How" , "to" };

s1[0].swap(s1[1]);

for (int i=0; i<2; i++) {

cout << s1[i];

}

return( 0 );

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Willetta
10 days ago
I'm going with D) It prints: to. Surely, the swap() function will only affect the first two elements, and the rest will be ignored, right?
upvoted 0 times
Fabiola
4 days ago
I think it prints: to
upvoted 0 times
...
...
Abel
16 days ago
Haha, this question is a classic! The answer is clearly B) It prints: toHow. Swapping the elements of a string array is like a magic trick, isn't it?
upvoted 0 times
...
Deandrea
23 days ago
I think the answer is A) It prints: Hoto. The swap() function will swap the elements of the string array, but the output will be concatenated.
upvoted 0 times
Blair
10 days ago
No, it actually prints: toHow.
upvoted 0 times
...
Jacqueline
13 days ago
I think the answer is A) It prints: Hoto.
upvoted 0 times
...
...
Kris
24 days ago
I think it prints: toHow because the swap function swaps the elements at index 0 and 1
upvoted 0 times
...
Magda
25 days ago
The correct answer is B) It prints: toHow. The swap() function will swap the elements of the string array, so the output will be reversed.
upvoted 0 times
Frank
4 days ago
Oh, I see. Thanks for clarifying!
upvoted 0 times
...
Deandrea
6 days ago
Actually, it prints: toHow
upvoted 0 times
...
Tijuana
11 days ago
No, I believe it prints: Hoto
upvoted 0 times
...
Dahlia
14 days ago
I think the answer is B) It prints: toHow
upvoted 0 times
...
...
Fernanda
26 days ago
I'm not sure, but I think it prints: toHow as well
upvoted 0 times
...
Brice
2 months ago
I believe it prints: toHow because the swap function swaps the elements in the array
upvoted 0 times
...
Long
2 months ago
I think it prints: toHow
upvoted 0 times
...

Save Cancel