What is the output of the following snippet?

Last Updated on May 3, 2022 by Admin 3

What is the output of the following snippet?

#include <iostream>
#include <string>
using namespace std;

int main()
{
   string s1 = "brick";
   string s2 = "block";
   string s;

   s1.swap(s2);
   s2.swap(s);
   s.swap(s2);
   cout << s1;
}
  • brick
  • It prints an empty string 
  • block
  • Compilation fails
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments