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

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77