BlackFriday 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 CPA Topic 2 Question 82 Discussion

Actual exam question for C++ Institute's CPA exam
Question #: 82
Topic #: 2
[All CPA 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:

Herminia
4 months ago
I think the correct answer is A) It prints: Hoto because the swap method is being used on the strings in the array.
upvoted 0 times
...
Marnie
4 months ago
I believe it will print 'Hoto' because 'How' is being swapped with 'to'.
upvoted 0 times
...
Antione
4 months ago
So, the answer would be either A) It prints: Hoto or B) It prints: toHow.
upvoted 0 times
...
Karina
5 months ago
I agree, it looks like it's swapping 'How' and 'to'.
upvoted 0 times
...
Walker
5 months ago
I think the code is swapping the positions of the strings in the array.
upvoted 0 times
...
Audry
5 months ago
I guess we'll find out the correct answer when we compile and run the code.
upvoted 0 times
...
Audry
5 months ago
I'm not sure, but I think it prints: Hoto.
upvoted 0 times
...
Janey
6 months ago
Because the swap function swaps the values of the elements, resulting in toHow.
upvoted 0 times
...
Herman
6 months ago
But why do you think it would be toHow?
upvoted 0 times
...
Janey
6 months ago
I believe it prints: Hoto.
upvoted 0 times
...
Herman
6 months ago
I think it prints: toHow.
upvoted 0 times
...

Save Cancel