Define a macro
swap(t, x, y)
that interchanges two arguments of typet
.(Block structure will help.)
The ideea is that a variable defined in a block structure exists only inside the block structure. So, I can create a temporary variable without affecting the code.
Here is my solution:
#include <stdio.h>
#define swap(t, x, y) {t tmp = x; x = y; y = tmp;}
int main() {
int x = 10, y = 2;
swap(int, x, y);
printf("%d %d", x, y);
return 0;
}