/* Demonstration of how easy swap operation becomes if done via 'memory location access' as opposed to changing via value. */ #include using namespace std; int main(){ double array_one[] = {1,2,3}; double array_two[] = {9,8,7}; double *left = array_one; double *right = array_two; for (int i =0; i< 3 ; i++) { cout << "Print add for array_one : " << &array_one[i] << " Print for array_two : "<< &array_two[i] << endl; } double * swap = left; left = right;//assignment operator right = swap; cout<< "CONFIRM VIA POINTERS" << endl; for (int i =0; i< 3 ; i++) { cout << "Print for array_one's pointer : " << &*left << " Print for array_two's pointer: "<< &*right << endl; ++left; ++right; } for (int i =0; i< 3 ; i++) { cout << "Print add for array_one : " << &array_one[i] << " and array_two: "<< &array_two[i] << endl; } //cout << "The values before are a= "<< a << " and b =" << b << endl; //swap (a,b) ; //cout << "The values now are a= "<< a << " and b =" << b << endl; return 0; }