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 4 Question 88 Discussion

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

Keneth
6 months ago
Haha, this code is like a linguistic tug-of-war! I think option B is the winner here.
upvoted 0 times
Venita
5 months ago
Yeah, the swap function switches the positions of the strings in the array.
upvoted 0 times
...
Whitley
5 months ago
I agree, option B is the correct answer.
upvoted 0 times
...
Milly
6 months ago
Exactly, it's like a linguistic tug-of-war!
upvoted 0 times
...
Bettina
6 months ago
User2
upvoted 0 times
...
Jaclyn
6 months ago
Yeah, it swaps the strings, so it should print 'toHow'.
upvoted 0 times
...
Roosevelt
6 months ago
User1
upvoted 0 times
...
Hyun
6 months ago
I think option B is correct.
upvoted 0 times
...
...
Ronald
7 months ago
Wow, this is a tricky one. I'm going to have to go with option B and hope I'm right.
upvoted 0 times
...
Selene
7 months ago
I'm going with option B. Swapping the strings should give us 'toHow'.
upvoted 0 times
...
Jacquline
7 months ago
Hmm, I'm not sure about this one. Let me think it through... Ah, got it! Option B it is.
upvoted 0 times
...
Micaela
7 months ago
The swap function should swap the contents of the strings, so I'm going to go with option B.
upvoted 0 times
Martina
6 months ago
I see, so the correct answer is: Hoto
upvoted 0 times
...
Yuette
6 months ago
Yes, that's correct. The swap function swaps the contents of the strings.
upvoted 0 times
...
Yuette
6 months ago
I think it prints: toHow
upvoted 0 times
...
Peggie
6 months ago
Really? I thought it would be: toHow
upvoted 0 times
...
Billy
6 months ago
No, it actually prints: Hoto
upvoted 0 times
...
Karrie
6 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