#include <iostream>
void swap(int *&a, int *&b)
{
int *tmp = a;
a = b;
b = tmp;
}
int main()
{
int i=1, j=2 ;
int* p_i = &i ;
int* p_j = &j ;
std::cout << "Before swap, i=" << i << " j=" << j << '\n';
std::cout << "Before swap, p_i=" << p_i << " p_j=" << p_j << "\n\n" ;
swap(p_i, p_j) ;
std::cout << "After swap, i=" << i << " j=" << j << '\n' ;
std::cout << "After swap, p_i=" << p_i << " p_j=" << p_j << '\n' ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdm9pZCBzd2FwKGludCAqJmEsIGludCAqJmIpIAp7CiAgICBpbnQgKnRtcCA9IGE7CiAgICBhID0gYjsKICAgIGIgPSB0bXA7Cn0KCmludCBtYWluKCkKewogICAgaW50IGk9MSwgaj0yIDsKIAogICAgaW50KiBwX2kgPSAmaSA7CiAgICBpbnQqIHBfaiA9ICZqIDsKIAogCiAgICBzdGQ6OmNvdXQgPDwgIkJlZm9yZSBzd2FwLCBpPSIgPDwgaSA8PCAiIGo9IiA8PCBqIDw8ICdcbic7CiAgICBzdGQ6OmNvdXQgPDwgIkJlZm9yZSBzd2FwLCBwX2k9IiA8PCBwX2kgPDwgIiBwX2o9IiA8PCBwX2ogPDwgIlxuXG4iIDsKICAgIHN3YXAocF9pLCBwX2opIDsKICAgIHN0ZDo6Y291dCA8PCAiQWZ0ZXIgc3dhcCwgaT0iIDw8IGkgPDwgIiBqPSIgPDwgaiA8PCAnXG4nIDsKICAgIHN0ZDo6Y291dCA8PCAiQWZ0ZXIgc3dhcCwgcF9pPSIgPDwgcF9pIDw8ICIgcF9qPSIgPDwgcF9qIDw8ICdcbicgOwp9