C++ PROGRAMING QUESTION Analyze the following program and choose one of the opti
ID: 3937054 • Letter: C
Question
C++ PROGRAMING QUESTION
Analyze the following program and choose one of the options below, substituting it in the highlighted section to make it run (only one option will work). Explain why choosing such instruction makes the program run. What is the output of the program? strcpy (s3, "three") s3=strcmp(s1+s2, "") s3="tree" strcmp(s3, "three") #include #include using namespace std; void h(string& s1, string& s2, string& s3); int main() {string strl="second"; string str2="first"; string str3="third"; h(strl, str2, str3); coutExplanation / Answer
Program :
#include <iostream>
#include <string>
using namespace std;
void h(string& s1,string& s2,string& s3);
int main()
{
string str1="second";
string str2="first";
string str3="third";
h(str1,str2,str3);
cout<<str1<<" "<<str2<<" "<<str3<<endl;
return 0;
}
void h(string& s1,string& s2,string& s3)
{
string t=s1;
s1=s2;
s2=t;
s3="tree";
}
Output :
first second tree
Choose : s3="tree";
Option c is correct choice.
Reason :
Since you can pass a string into a function as an argument and take a string reference as a parameter in the function we dont perform srcmp and strcpy only assignment is performed.
Therefore s3="tree"; is valid.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.