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 5 Question 93 Discussion

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

Willetta
4 months ago
I'm going with D) It prints: to. Surely, the swap() function will only affect the first two elements, and the rest will be ignored, right?
upvoted 0 times
Lynelle
3 months ago
Yeah, I agree. The swap() function only affects the first two elements.
upvoted 0 times
...
Fabiola
4 months ago
I think it prints: to
upvoted 0 times
...
...
Abel
4 months ago
Haha, this question is a classic! The answer is clearly B) It prints: toHow. Swapping the elements of a string array is like a magic trick, isn't it?
upvoted 0 times
...
Deandrea
4 months ago
I think the answer is A) It prints: Hoto. The swap() function will swap the elements of the string array, but the output will be concatenated.
upvoted 0 times
Alfreda
3 months ago
Oh, I see. Thanks for clarifying!
upvoted 0 times
...
Blair
4 months ago
No, it actually prints: toHow.
upvoted 0 times
...
Jacqueline
4 months ago
I think the answer is A) It prints: Hoto.
upvoted 0 times
...
...
Kris
4 months ago
I think it prints: toHow because the swap function swaps the elements at index 0 and 1
upvoted 0 times
...
Magda
4 months ago
The correct answer is B) It prints: toHow. The swap() function will swap the elements of the string array, so the output will be reversed.
upvoted 0 times
Frank
4 months ago
Oh, I see. Thanks for clarifying!
upvoted 0 times
...
Deandrea
4 months ago
Actually, it prints: toHow
upvoted 0 times
...
Tijuana
4 months ago
No, I believe it prints: Hoto
upvoted 0 times
...
Dahlia
4 months ago
I think the answer is B) It prints: toHow
upvoted 0 times
...
...
Fernanda
4 months ago
I'm not sure, but I think it prints: toHow as well
upvoted 0 times
...
Brice
5 months ago
I believe it prints: toHow because the swap function swaps the elements in the array
upvoted 0 times
...
Long
5 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