To swap two variables in a function you must pass their addresses. Otherwise the function only swaps copies.
To swap two variables inside a helper, the helper must receive their addresses. Otherwise it only swaps copies, and main’s x and y never notice. After a real swap, 3 and 7 become 7 and 3.
before
call
write
after
Each step highlights the matching C line. Program output appears only when a line that prints actually runs.
Five questions. Pick one answer each, then Check answers. The correct choice turns green.
1. After swap, x y print:
Swapped.
2. Why &x and &y?
Pass addresses.
3. int t = *a copies:
Temp.
4. A swap of copies (no pointers) would:
Need pointers.
5. swap is void because:
Out-parameters.