How can one swap pointer addresses within a function with a signature?
Let\'s say:
int weight, height;
void swap(int* a, int* b);
S
The new answer (since the question has been reformulated)
is that addressed of variables are determined at compile time and can therefore not be swapped. Pointers to variables however can be swapped.
Old answer: this was the answer when the question still implied swapping the values of 2 variables by means of a function:
function call:
int width=10, height=20;
swap(&width, &height)
implementation:
void swap(int *a, int *b)
{
int temp;
temp=*a;
*a = *b;
*b = temp;
}
or...without using a temporary variable: ;^)
void swap(int *a, int *b)
{
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
do watch out that the last method breaks for the case: swap (&a, &a). Very sharply pointed out by user9876 in the comments.