int main() {
// Complete the program
string a,b;
getline(cin,a);
getline(cin,b);
cout<<a.size()<<" ";
cout<<b.size();
string c=a+b;
cout<<endl<<c;
swap(a[0],b[0]);
cout<<endl<<a<<" "<<b;
return 0;
}
void swap(string s1,string s2){
string temp=s1;
s1=s2;
s2=temp;
}
Well the target is to swap the first element of both strings, but I created a general function for that and even got it right. But, unexpectedly, I didn't use pass by reference or pointer! Even then, the changes are permanent when I try to output a and b in the end!
Logically it shouldn't work but it is working. Is it something to do with the strings?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…