← Pointers: What They Actually Are

Swap Two Variables

hard

Swap a and b’s values – but do every read and write through pa and pb, never by writing a or b directly. You’ll still need one ordinary temporary variable to hold a value mid-swap, exactly like a swap without pointers would; the only thing that changes is that every access to a and b themselves goes through a pointer instead.

This is worth getting comfortable with by hand here, in main, because the very next lesson wraps this identical logic inside a function – at which point it stops being optional and becomes the only way to write a function that can swap its caller’s variables at all.

Your solution

"Run" uses the sample stdin ("3 7"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution