basics · beginner · ~15 min
Mutate caller variables via pointers.
Exchange the values of two variables through pointers.
Implement void swap_int(int *a, int *b) that swaps the integers pointed to by a and b, so that after the call *a holds the old *b and vice versa. No main — the grader calls it.
Two non-NULL pointers a and b to ints.
No return value. After the call, the two pointed-to values are exchanged.
x = 3, y = 7; swap_int(&x, &y) -> x == 7, y == 3
p = 1, q = 1; swap_int(&p, &q) -> p == 1, q == 1
Two non-NULL int pointers a and b.
No return value; the two pointed-to values are exchanged.
void swap_int(int *a, int *b) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.