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 8 Question 91 Discussion

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

Eun
2 months ago
I think it prints: toHow too, the swap function swaps the elements in the array
upvoted 0 times
...
Marge
2 months ago
Haha, this question is like a linguistic version of 'the chicken or the egg'. I'm just gonna try to swap my brain with the compiler and see what happens.
upvoted 0 times
...
Nathan
2 months ago
This is a tricky one! I'm gonna guess C) It prints: Ht. Maybe the swap() function somehow cuts the strings in half or something. Who knows?
upvoted 0 times
...
Alpha
2 months ago
Hmm, I'm not sure about this one. I'll go with D) It prints: to, just to be safe. Can't go wrong with the simplest option, right?
upvoted 0 times
Christiane
8 days ago
User4: I agree with User3, it's probably: Hoto
upvoted 0 times
...
Orville
9 days ago
User3: I'm going with: Hoto
upvoted 0 times
...
Murray
13 days ago
User2: No, I believe it prints: Ht
upvoted 0 times
...
Theresia
20 days ago
User1: I think it prints: to
upvoted 0 times
...
...
Lashunda
2 months ago
I'm not sure, but I think it prints: toHow as well
upvoted 0 times
...
Marquetta
2 months ago
I believe it prints: toHow because the swap function swaps the elements in the array
upvoted 0 times
...
Genevive
2 months ago
I think the answer is A) It prints: Hoto. The swap() function should reverse the order of the strings in the array.
upvoted 0 times
Alita
26 days ago
User2: Correct, the output would be Hoto.
upvoted 0 times
...
Lillian
1 months ago
User1: I think the answer is A) It prints: Hoto. The swap() function should reverse the order of the strings in the array.
upvoted 0 times
...
...
Marisha
2 months ago
I think it prints: toHow
upvoted 0 times
...
Nina
2 months ago
The correct answer is B) It prints: toHow. The swap() function swaps the contents of the string objects s1[0] and s1[1], so the output should be 'toHow'.
upvoted 0 times
Buck
1 months ago
User2: That's correct! The swap() function swaps the contents of the string objects s1[0] and s1[1].
upvoted 0 times
...
Xenia
1 months ago
User1: I think it prints: toHow
upvoted 0 times
...
...

Save Cancel