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

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

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

Save Cancel