viewing paste swap | C++

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <cstring>
using namespace std;
 
void swapTest(char*& name_1, char*& name_2){
       
        char * tmp = name_2;
        name_2 = name_1;
        name_1 = tmp;
       
}
 
int main () {
       
        char* name_1 = new char[20];
        char* name_2 = new char[20];
       
        strcpy(name_1,"Joseph");
        strcpy(name_2,"Marc");
       
        cout << name_1 << " " << name_2<<endl;
       
        swapTest(name_1,name_2);
       
        cout << name_1 << " " << name_2;
       
        return 0;
}
 
Viewed 414 times, submitted by Streusel.