Question: Can you explain what this C++ code doing and give the detailed explanation of why the code does what it does. What is the output
Can you explain what this C++ code doing and give the detailed explanation of why the code does what it does.
What is the output of the following code? (You may assume that the file has all of the necessary #includes, etc).
1 string x = "one \"two\" three four"; 2 string y = "\"fivesix seveneight\""; 3 cout << x.length() <<" "; 4 cout << y.length() << " "; 5 string z; 6 7 if (x.length() <= y.length()) { 8 z = y+x; 9 } 10 else { 11 z = x+y; 12 } 13 string the_new_one = ""; 14 for (int i = 0; i < z.length(); ++i) { 15 if (i % 3 == 0) { 16 the_new_one += z.substr(i, 1); 17 } 18 } 19 cout << "" << the_new_one << " ";
Answer: 21 20 o w r oviseit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
