When this code for swapping two string is being executed I get undesired outputs
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a2[] = "Hello world";
char a1[] = "Geek";
char a3[20];
cout<<a2<<endl<<a1<<endl;
strcpy(a3,a1);
strcpy(a1,a2);
strcpy(a2,a3);
cout<<a2<<endl<<a1<<endl;
}
I get these results:
Hello world
Geek
Geek
HelloGeek (I expect it to be HelloWorld)
Is there something I'm doing wrong in the code.