#include using namespace std; // Prepare > C++ > Introduction: Pointer ostream& operator<<(ostream& os, const pair& p) { return os << "(" << p.first << "," << p.second << ")"; } void update(int *a,int *b) { // Modify the values in memory so that a contains their sum // and b contains their absoluted dfference. int c = *a; int d = *b; *a = c + d; *b = abs(c-d); } int main() { vector,pair>> testCases = { {{4,5}, {9,1} }, {{0,7}, {7,7} }, }; for (auto& tc: testCases) { int a = get<0>(tc).first, b = get<0>(tc).second; int *pa = &a, *pb = &b; update(pa, pb); pair result = {a,b}; pair expected =get<1>(tc); int width = 10; cout << setw(width) << "input: " << get<0>(tc) << endl; cout << setw(width) << "result: " << result << endl; cout << setw(width) << "expected: " << expected << endl; cout << (result == expected ? "\033[32mpassed\033[0m" : "\033[31mfailed\033[0m") << endl; cout << "----------------------------\n"; } return 0; }