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 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
5 months ago
Haha, this code is like a linguistic tug-of-war! I think option B is the winner here.
upvoted 0 times
Venita
4 months ago
Yeah, the swap function switches the positions of the strings in the array.
upvoted 0 times
...
Whitley
4 months ago
I agree, option B is the correct answer.
upvoted 0 times
...
Milly
5 months ago
Exactly, it's like a linguistic tug-of-war!
upvoted 0 times
...
Bettina
5 months ago
User2
upvoted 0 times
...
Jaclyn
5 months ago
Yeah, it swaps the strings, so it should print 'toHow'.
upvoted 0 times
...
Roosevelt
5 months ago
User1
upvoted 0 times
...
Hyun
5 months ago
I think option B is correct.
upvoted 0 times
...
...
Ronald
6 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
6 months ago
I'm going with option B. Swapping the strings should give us 'toHow'.
upvoted 0 times
...
Jacquline
6 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
6 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
5 months ago
I see, so the correct answer is: Hoto
upvoted 0 times
...
Yuette
5 months ago
Yes, that's correct. The swap function swaps the contents of the strings.
upvoted 0 times
...
Yuette
5 months ago
I think it prints: toHow
upvoted 0 times
...
Peggie
5 months ago
Really? I thought it would be: toHow
upvoted 0 times
...
Billy
5 months ago
No, it actually prints: Hoto
upvoted 0 times
...
Karrie
5 months ago
I think it prints: toHow
upvoted 0 times
...
...

Save Cancel